实现这功能首先,小程序端添加业务域名 PHP代码
实现这功能首先,小程序端添加业务域名
PHP代码
['path'=>'/pages/index/index','query'=>$scheme['name']]]; $tokenurl = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $appid . '&secret=' . $secret; $data = file_get_contents($tokenurl); $data = json_decode($data, true); $token = $data['access_token']; $url = "https://api.weixin.qq.com/wxa/generatescheme?access_token=" . $token; $data = $this->curl_post($url, null, $body); if ($data['errmsg'] == 'ok'){ return json(['code' => 200,'data'=>$data['openlink'], 'msg' =>'操作成功']); }else{ return json(['code' => 201,'data'=>$data, 'msg' =>'异常']); } } function curl_post($url,$herder,$body){//一般框架都会自带GuzzleHttp,没有的请手动安装,或者利用curl post请求 $client = new \GuzzleHttp\Client(); try { $pram = $client->post($url,[ 'headers'=>$herder, 'json'=>$body, ]); $content = json_decode($pram->getBody()->getContents(),true); return $content; }catch (ErrorException $exception){ return $exception->getCode(); } }}
下面使用js的location.href
location.href = 'https://***.***.com'
我前端用的是uniapp,Vue的话要安装axiOS或者jq
短信内容放前端链接地址,这样就可以通过打开游览器跳转到小程序了
注意
必须是发布的小程序才会被唤醒
接口有上限,如果需求不高不用理会
解决方法就是在请求的时候用Redis存储url scheme返回的地址和请求时间, 设置一段时间再次发送新的请求再次覆盖存储数据
来源地址:https://blog.csdn.net/weixin_43453621/article/details/132753162
--结束END--
本文标题: php版 短信跳转微信小程序
本文链接: https://www.lsjlt.com/news/427748.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0