1
$wxapp = new Wxapp($config);
$res = $wxapp->getTempShortUrl('pages/shop/', '?ru_id='.$ru_id.'&wxapp='.$is_wxapp);
$res = json_decode($res, true);
if ($res) {
$url = isset($res['link']) ? $res['link'] : '';
}
2
public function getTempShortUrl($path = '', $query = '',$page_title='店铺首页',$is_permanent = true)
{
// 先取缓存
$cache_id = md5('wxapp_short_scheme_' . $path . '_' . $query);
if (($temp_arr = $this->getCache($cache_id)) && !empty($temp_arr)) {
return $temp_arr;
}
if (!$this->checkAuth()) {
return false;
}
$page_url = $query ? $path.$query : $path;
$data = ['page_url' => $page_url,'page_title'=>$page_title,'is_permanent'=>$is_permanent];
$result = $this->curlPost(self::API_URL_PREFIX . self::GEN_SHORT_SCHEME . 'access_token=' . $this->access_token, self::json_encode($data));
if ($result) {
$json = json_decode($result, true);
if (!empty($json['errcode'])) {
$this->errCode = $json['errcode'];
$this->errMsg = $json['errmsg'];
return $this->checkRetry(__FUNCTION__, func_get_args());
}
$this->setCache($cache_id, $result, 60 * 60 * 24 * 3600);
return $result;
}
return false;
}