三维家设计官网(H5页面附带参数跳转到小程序)
用户投稿
•
•
阅读 155
三维家设计官网:H5页面附带参数跳转到小程序。

小程序在Onload中接受传递数据【optinos.var】
h5页面请求php鉴权接口获取小程序链接(通过local.hrdf跳转小程序)
前端请求getUrlScheme(附带参数)
public function wx_xcx_code($appid, $appsecret){
// 获取access_token、有效时间
$access_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$appsecret;
$access_info = json_decode(file_get_contents($access_url),true);
return $access_info;
}
/**
* 第二步 拼接接口及请求参数 调用POST请求 返回结果
*/
public function getUrlScheme(){
$access_token = $this->wx_xcx_code("appid", "小程序秘钥);
$access_token = $access_token['access_token']; // 加个判断,是否获取成功
$url = "https://api.weixin.qq.com/wxa/generatescheme?access_token=" . $access_token;
$path = '/pages/index/index';
//query 跳转传递的参数
$scene = 'phone='.input('phone');
$post_data = [
'jump_wxa' => [
'path' => $path,
'query' => $scene
],
'is_expire' => true,
'expire_time' => time()+3600
];
$post_data = json_encode($post_data);
$result = $this->api_notice_increment($url, $post_data);
$res = $this->object_array(json_decode($result));
return json($res['openlink']);
}
//对象转数组
public function object_array($array){
if(is_object($array)) {
$array = (array)$array;
}
if(is_array($array)) {
foreach($array as $key=>$value) {
$array[$key] = $this->object_array($value);
}
}
return $array;
}
/**
* 发起 POST 请求微信接口
* https://api.weixin.qq.com/wxa/generatescheme?access_token=ACCESS_TOKEN
* 返回结果
*/
public function api_notice_increment($url, $data){
$ch = curl_init();
$header = ["Accept-Charset" => "utf-8"];
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$tmpInfo = curl_exec($ch);
// var_dump($tmpInfo);
if (curl_errno($ch)) {
return false;
} else {
// var_dump($tmpInfo);
return $tmpInfo;
}
}
随机文章
SEO小小课堂网SEO教程
友情链接交换
搜素引擎算法
关键词排名优化
GEO培训
SEO教程
站长导航
百度搜索“网赚联盟”即可找到本站,微信搜索“小小课堂网”关注小小课堂网公众号。网赚联盟( wangzhuan.org.cn )欢迎用户投稿,发布者:用户投稿,文章版权归作者所有,投稿文章不代表网赚联盟立场,中二少年发布为网赚联盟原创文章,转载请注明出处:https://wangzhuan.org.cn/24996.html

微信扫一扫
支付宝扫一扫