• <abbr id="chdyf"></abbr>
    <ruby id="chdyf"><acronym id="chdyf"><meter id="chdyf"></meter></acronym></ruby>
    <bdo id="chdyf"></bdo>
    <dfn id="chdyf"><menu id="chdyf"></menu></dfn>
    1. <menuitem id="chdyf"></menuitem><strong id="chdyf"><menu id="chdyf"></menu></strong>

      <rt id="chdyf"><menu id="chdyf"></menu></rt>
      成人小说一区二区三区,伊人精品成人久久综合全集观看,久久HEZYO色综合,中文字幕精品人妻熟女,影音先锋成人网站,我要看免费一级毛片,中国女人做爰A片,中文字幕av久久爽Av

      微信小程序發(fā)送訂閱消息(之前是模板消息)

      2020-8-20    seo達(dá)人

      之前的模板消息已經(jīng)廢棄,現(xiàn)在改為訂閱消息,訂閱消息發(fā)布前,需要用戶確認(rèn)后才能接收訂閱消息。


      image


      小程序端

      index.wxml


      <button bindtap="send">發(fā)送訂閱消息</button>

      index.js


      const app = getApp()

      Page({ data: {

       }, send:function(){

         wx.requestSubscribeMessage({ tmplIds: ['WZiCliW1zVtHXqX7dGnFNmFvxhW-wd9S_W4WfrwNvss'],


      success:(res)=> { // 在登錄的時(shí)候,獲取到的openid進(jìn)行緩存,現(xiàn)在直接把openid提取出來即可 wx.getStorage({ key: 'openid',


               success (res) { console.log(res.data)

                 wx.request({ url: 'https://www.xxx.com/send.php?openid='+res.data, data: {},


      header: { 'content-type': 'application/json' },


                   success (res) { // 推送 if(res.data.errcode == '43101'){ console.log("拒絕訂閱消息")

                     }else if(res.data.errcode == '0'){ console.log("發(fā)送訂閱消息")

                     }else{ console.log("未知錯(cuò)誤")

                     }

                   }

                 })

               },

               fail (res) { console.log("沒有openid,無法發(fā)送")

               }

             })

           }

         })

       }

      })

      后端

      <?php //設(shè)置 header  header("Content-type:application/json"); //接收參數(shù) $openid = $_GET["openid"];


      //初始化 CURL $ch = curl_init(); // 獲取access_token // include ''; require_once("access_token.php");


      //目標(biāo)服務(wù)器地址  curl_setopt($ch, CURLOPT_URL,


      'https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token='.$access_token);


      //設(shè)置要POST的數(shù)據(jù) curl_setopt($ch, CURLOPT_POST, true);


      $data = '{

       "touser": "'.$openid.'",

       "template_id": "模板ID",

       "page": "pages/index/index",// 要跳轉(zhuǎn)的頁面

       "lang":"zh_CN",

       "data": {

           "thing4": {

               "value": "歡迎使用專插本最前線小程序"

           },

           "thing5": {

               "value": "小程序由公眾號(hào):廣東專插本最前線開發(fā)"

           }

       }

      }';

      curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

      curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); // 對(duì)認(rèn)證證書來源的檢查 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // 從證書中檢查SSL加密算法是否存在 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); //獲取的信息以文件流的形式返回,而不是直接輸出 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //發(fā)起請(qǐng)求 $result = curl_exec($ch); echo $result; //關(guān)閉請(qǐng)求 curl_close($ch); ?>

      access_token.php


      <?php // 聲明頁面header header("Content-type:charset=utf-8"); // APPID、APPSECRET $appid = "你的小程序APPID";

      $appsecret = "你的小程序APPSECRET"; // 獲取access_token和jsapi_ticket function getToken(){

         $file = file_get_contents("access_token.json",true);//讀取access_token.json里面的數(shù)據(jù) $result = json_decode($file,true); //判斷access_token是否在有效期內(nèi),如果在有效期則獲取緩存的access_token //如果過期了則請(qǐng)求接口生成新的access_token并且緩存access_token.json if (time() > $result['expires']){

             $data = array();

             $data['access_token'] = getNewToken();

             $data['expires'] = time()+7000;

             $jsonStr =  json_encode($data);

             $fp = fopen("access_token.json", "w");

             fwrite($fp, $jsonStr);

             fclose($fp); return $data['access_token'];

         }else{ return $result['access_token'];

         }

      } //獲取新的access_token function getNewToken($appid,$appsecret){ global $appid; global $appsecret;

         $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$appsecret."";

         $access_token_Arr =  file_get_contents($url);

         $token_jsonarr = json_decode($access_token_Arr, true); return $token_jsonarr["access_token"];

      }


      $access_token = getToken(); ?>

      邏輯

      1、通過button控件出發(fā)send函數(shù)

      2、send函數(shù)調(diào)用wx.requestSubscribeMessageAPI,微信允許接收訂閱消息

      3、 wx.request向send.php后端請(qǐng)求

      4、后端獲取access_token后,調(diào)用訂閱消息接口POST一段json數(shù)據(jù)即可發(fā)送訂閱消息


      官方文檔

      1、https://developers.weixin.qq.com/miniprogram/dev/api/open-api/subscribe-message/wx.requestSubscribeMessage.html


      2、https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.addTemplate.html


      Author:TANKING

      Date:2020-08-24

      Web:http://www.likeyun.cn/

      WeChat:face6009

      藍(lán)藍(lán)設(shè)計(jì)m.wtxcl.cn )是一家專注而深入的界面設(shè)計(jì)公司,為期望卓越的國內(nèi)外企業(yè)提供卓越的UI界面設(shè)計(jì)、BS界面設(shè)計(jì) 、 cs界面設(shè)計(jì) 、 ipad界面設(shè)計(jì) 、 包裝設(shè)計(jì) 、 圖標(biāo)定制 、 用戶體驗(yàn) 、交互設(shè)計(jì)、 網(wǎng)站建設(shè) 、平面設(shè)計(jì)服務(wù)

      日歷

      鏈接

      個(gè)人資料

      存檔

      主站蜘蛛池模板: 国内精品人人妻少妇视频| 夊夊夊夂夂夂夂夂夂夂亚洲亚洲亚洲亚洲色色色 | 国产熟女在线看| 亚洲国产制服丝袜 | 中文字字幕在线中文乱码| 德清县| 浮力影院欧美三级日本三级| 亚洲综合色婷婷七月丁香| 日韩无码2020| 亚洲avav| 国产主播在线 | 中文| AV无码一区二区三区四区| 亚洲熟女精品| 久久99人妻无码精品一区| 夜夜嗨av一区二区三区四季av| 张家口市| 香蕉久久久久成人麻豆AV影院| 狼狼狼色精品视频在线播放| 久久久久久久久熟女AV| 妇女自拍偷自拍亚洲精品| 日韩少妇人妻VS中文字幕| 超碰碰97| 日本一区二区三区久久久| 成人欧美| 99在线热视频只有精品免费| 91综合色| jizzjizz视频| 欧美成人午夜精品免费福利| 影音先锋91| 亚洲三区av| 久久这里只有精品23| 精品99视频| 伊人超碰| 亚洲男人天堂| 亚洲国产精品嫩草影院久久| 无码人妻AV一区二区| 大邑县| 黄床大片免费30分钟国产精品| 伊人性网| 亚洲AV电影网| 无码av波多野结衣久久|