微信订阅号开发笔记(三)
生活随笔
收集整理的這篇文章主要介紹了
微信订阅号开发笔记(三)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、接收語音識別結果
if($msgType=="voice"){//收到語音消息//MediaId 語音消息媒體id,可以調用多媒體文件下載接口拉取數據。//Format 語音格式,如amr,speex等$format = $postObj->Format;$mediaId = $postObj->MediaId;//開通語音識別功能,用戶每次發送語音給公眾號時,微信會在推送的語音消息XML數據包中,增加一個Recongnition字段。//注:由于客戶端緩存,開發者開啟或者關閉語音識別功能,對新關注者立刻生效,對已關注用戶需要24小時生效。開發者可以重新關注此帳號進行測試。$recognition = $postObj->Recognition;$contentStr = "Welcome to wechat world! Format ".$format." MediaId ".$mediaId." Recognition ".$recognition." ok ";$this->responseMsgText($fromUsername, $toUsername, $time, $contentStr ); }2、發送客服消息
? ? ? ?當用戶主動發消息給公眾號的時候(包括發送信息、點擊自定義菜單、訂閱事件、掃描二維碼事件、支付成功事件、用戶維權),微信將會把消息數據推送給開發者,開發者在一段時間內(目前修改為48小時)可以調用客服消息接口,通過POST一個JSON數據包來發送消息給普通用戶,在48小時內不限制發送次數。此接口主要用于客服等有人工消息處理環節的功能,方便開發者為用戶提供更加優質的服務。
獲取u
//發送客服消息public function sendMessage(){$url="https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=";$url.=$this->getacctoken();//可發送 文本 圖片 語音 視頻 音樂 圖文 模版詳見http://mp.weixin.qq.com/wiki/index.php?title=%E5%8F%91%E9%80%81%E5%AE%A2%E6%9C%8D%E6%B6%88%E6%81%AF$post_data='{"touser":"a openId ","msgtype":"text","text":{"content":"Hello World"}}';$ret = $this->cpost($url,$post_data);print_r( $ret );}3、基礎 獲取access_token
//獲取access_token //查找數據庫 發現過期 重新獲取 存入數據庫 // 有效期內 返回存儲的access_token public function getacctoken(){$url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".APPID."&secret=".APPSECRET;$accesstoken = M("accesstoken"); // 實例化wlog對象$atoken = $accesstoken ->where('aid=1 ')->find();$time = time();if($atoken){$expires_in=$accesstoken ->where('aid=1')->getField('expires_in');if($time>=$expires_in){$adata = $this->cget($url);echo "time is = ".$time."access_token = ".$adata['access_token'];$data['access_token']= $adata['access_token'];$data['expires_in']=$time + $adata['expires_in'];$accesstoken->where('aid=1')->save($data);return $adata['access_token'];}else{return $accesstoken ->where('aid=1')->getField('access_token');}}else{$adata = $this->cget($url);echo "time is = ".$time."access_token = ".$adata['access_token'];$data['access_token']= $adata['access_token'];$data['expires_in']=$time + $adata['expires_in'];$accesstoken->where('aid=1')->save($data);return $adata['access_token'];} }轉載于:https://blog.51cto.com/3409736/1408112
總結
以上是生活随笔為你收集整理的微信订阅号开发笔记(三)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: POJ 3041Asteroids 二分
- 下一篇: CentOS 6.3下Samba服务器的