開放標簽使用步驟
注意:必須真機測試!!!
這塊是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."×tamp=".$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
公眾號