<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                #### 前端DEMO - wxml ```php <view clas="index" style="background: white"> <button bindtap="clickss">觸發一下</button> </view> ``` - wxjs ```javascript clickss:function (){ const templateId = 'RZM7nZoN5P2sA1m6aeiPMmZ-90U1_8PFmjrv_Nf5bhk'; // 訂閱消息模版id wx.requestSubscribeMessage({ tmplIds: [templateId], success(res) { if (res[templateId] == 'accept') { //用戶同意了訂閱,允許訂閱消息 wx.showToast({ title: '訂閱成功' }) } else { //用戶拒絕了訂閱,禁用訂閱消息 wx.showToast({ title: '訂閱失敗' }) } }, fail(res) { console.log('ooooooooooooooo', res) }, complete(res) { console.log(res) } }) }, ``` #### 后端推送代碼 ```php namespace app\api\controller; use app\common\controller\Api; use fast\Http; use think\Cache; class SubtoMsg extends Api { protected $noNeedLogin = ['*']; protected $noNeedRight = ['*']; /** * @return mixed * 獲取access_token * 時效3600秒 */ public function getaccess_tonken() { if (Cache::has('token')) { return Cache::get('token'); } else { $appid = ''; $appsecret = ''; $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $appsecret; //api接口 $content = Http::get($url); if ($content) { $content = json_decode($content, true); } if (!empty($content['access_token'])) { session('access_token', $content['access_token']); Cache::set('token', $content['access_token'], 3600); return $content['access_token']; } } } /** * @param $openid 目標用戶openid * @param $send 發送數據串 */ public function send($send) { /* $send格式demo $openid = 'o9vhc5BxMc1pTNCzD1IWVuy4JUP0';//目標用戶的openid $templateId = 'laOhzjVJ5J9Tz97JOM4FNlMud2bkwV-g5DPuTYsWUyA'; $data = array( 'phrase1' => array('value' => '劉洋'), 'time2' => array('value' => date('Y-m-d H:i:s', time())), 'thing3' => array('value' => "老王很棒的喲", 'color' => '#333333'), ); $send = array( "touser" => $openid, "template_id" => $templateId, "data" => $data, );*/ $access_token = self::getaccess_tonken(); $url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" . $access_token; $ret = Http::post($url, urldecode(json_encode($send))); $this->success('', json_decode($ret)); /* * 發送成功 * { "code": 1, "msg": "", "time": "1619316449", "data": { "errcode": 0, "errmsg": "ok", "msgid": 1840866241775747074 } }*/ /* * 失敗的情況 * { "code": 1, "msg": "", "time": "1619316019", "data": { "errcode": 43101, "errmsg": "user refuse to accept the msg rid: 6084cd33-3bd5fcdb-4ed3439f" } }*/ } //用于測試 public function send_text() { $openid = 'o9vhc5BxMc1pTNCzD1IWVuy4JUP0';//目標用戶的openid // $templateId="";//訂閱消息的模板id $templateId = 'laOhzjVJ5J9Tz97JOM4FNlMud2bkwV-g5DPuTYsWUyA'; // $templateId = get_addon_config('dymsg')['noticetemplateid']; $data = array( 'phrase1' => array('value' => '劉洋'), 'time2' => array('value' => date('Y-m-d H:i:s', time())), 'thing3' => array('value' => "老劉很棒的喲", 'color' => '#333333'), ); $access_token = self::getaccess_tonken(); $url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" . $access_token; $send = array( "touser" => $openid, "template_id" => $templateId, "data" => $data, ); $ret = Http::post($url, urldecode(json_encode($send))); $this->success('', json_decode($ret)); /* * 發送成功 * { "code": 1, "msg": "", "time": "1619316449", "data": { "errcode": 0, "errmsg": "ok", "msgid": 1840866241775747074 } }*/ /* * 失敗的情況 * { "code": 1, "msg": "", "time": "1619316019", "data": { "errcode": 43101, "errmsg": "user refuse to accept the msg rid: 6084cd33-3bd5fcdb-4ed3439f" } }*/ } } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看