iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > PHP编程 >php版 短信跳转微信小程序
  • 299
分享到

php版 短信跳转微信小程序

php微信小程序开发语言 2023-10-10 21:10:25 299人浏览 独家记忆
摘要

实现这功能首先,小程序端添加业务域名  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();        }    }}

下面使用jslocation.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文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作