小程序跳转按钮:


 

开放标签使用步骤

 

注意:必须真机测试!!!

 

这块是HTML页面

<wx-open-launch-weapp id="launch-btn" username="所需跳转的小程序原始id" path="所需跳转的小程序内页面路径及参数">
  <template>
    <button>进入小程序</button>
  </template>
</wx-open-launch-weapp>
<script type="text/javascript" src="https://res2.wx.qq.com/open/js/jweixin-1.6.0.js"></script> <script type="text/javascript"> wx.config({ debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 appId: "公众号APPID", // 必填,公众号的唯一标识 timestamp: "生成签名的时间戳", // 必填, nonceStr: "生成签名的随机串", // 必填, signature: "签名", // 必填, jsApiList: ["scanQRCode"], // 必填,需要使用的JS接口列表 openTagList:['wx-open-launch-weapp'] }); </script>

 

这块获取签名的

/**
 * 获取access_token
 * $appid:开发者ID(AppID)
 * $appsecret:开发者密码(AppSecret)
 *
 * 返回access_token、有效时间
 */
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;
}



/**
 * 获取jsapi_ticket  GET请求 返回结果  然后加密获取signature
 */
function  getSignature(){
    $access_token = wx_xcx_code("公众号开发者ID-AppID", "公众号的开发者密码-AppSecret");
$access_token = $access_token['access_token']; // 加个判断,是否获取成功 $url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=".$access_token."&type=jsapi"; // 获取jsapi_ticket、有效时间、返回状态、返回提示 $sign = json_decode(file_get_contents($url),true); $noncestr = "asdasdasdasdsdas"; // 生成随机串,这里写死做测试 $timestamp = time(); // 当前时间戳 $base_url = "http://域名/test.html"; // 当前网页的URL,不包含#及其后面部分 // sha1加密得到signature (签名) $sha1_info = "jsapi_ticket=".$sign['ticket']."&noncestr=".$noncestr."&timestamp=".$timestamp."&url=".$base_url; $signature = sha1($sha1_info);
print_r($signature); }

 

 

 

参考资料:

https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_Open_Tag.html

公众号


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM