中字幕视频在线永久在线观看免费-色偷偷88888欧美精品久久久-性生交大片免费看女人按摩-3d动漫精品啪啪一区二区下载

行業(yè)動態(tài)

了解最新公司動態(tài)及行業(yè)資訊

當前位置:首頁>新聞中心>行業(yè)動態(tài)
全部 4136 公司動態(tài) 1000 行業(yè)動態(tài) 3136

如何把微信公眾號授權給開發(fā)者服務器2與微信服務器進行

時間:2022-08-06   訪問量:2241

文章目錄

很多人都有自己的服務器。尤其是對大學生來說服務器運維服務器運維,很多服務器公司對中學生都是有利的。比如騰訊云每個月只要1塊錢:所以作為程序員,我們總是想自己掌控一切。在手,如何使用我們的開發(fā)者服務器管理陌陌公眾號?這就是本文所涵蓋的內(nèi)容。

本文介紹了以下內(nèi)容:

1 如何將陌陌公眾號授權給開發(fā)者服務器 2 如何使用代碼將開發(fā)者服務器與陌陌服務器關聯(lián)


/**
 * 微信公眾號開發(fā)-入門
 *
 * api
 */
define("TOKEN",'we--xxxx');   //這里和你微信公眾號開放平臺上的tonken填寫一樣的即可
$weixinApi=new WeixinApi();
if(isset($_GET["echostr"])){
    $weixinApi->valid();
}else{
    $weixinApi->responseMsg();
}
class WeixinApi{
    //驗證接口
    public function valid(){
        $echoStr = $_GET["echostr"];//從微信用戶端獲取一個隨機字符賦予變量echostr
        if($this->checkSignature()){
            echo $echoStr;
            exit;
        }
    }
    //檢查簽名
    private function checkSignature(){
        //1 接受微信服務器get請求發(fā)送過來的4個參數(shù)
        $signature = $_GET["signature"];//從用戶端獲取簽名賦予變量signature
        $timestamp = $_GET["timestamp"];//從用戶端獲取時間戳賦予變量timestamp
        $nonce = $_GET["nonce"];    //從用戶端獲取隨機數(shù)賦予變量nonce
        //2 加密和校驗請求
        //2.1 將token、timestamp、nonce三個參數(shù)進行字典序排序
        $tmpArr = array(TOKEN, $timestamp, $nonce);//簡歷數(shù)組變量tmpArr
        sort($tmpArr, SORT_STRING);//新建排序
        //2.2 將三個參數(shù)字符串拼接成一個字符串進行sha1加密

服務器運維_運維服務口號大全_運維服務服務器網(wǎng)絡設備日常巡檢報告

$tmpStr = implode($tmpArr);//數(shù)組轉字符串 $tmpStr = sha1($tmpStr);//shal加密 //2.3 開發(fā)者獲得加密后的字符串可與signature對比,標識該請求來源于微信 if ($tmpStr == $signature) { return true; } else { return false; } } //回復消息 public function responseMsg(){ //3 以下代碼接受消息 //3.1 接受微信服務器發(fā)送過來的原生的POST的數(shù)據(jù)包 // $postData = $GLOBALS["HTTP_RAW_POST_DATA"]; $postData = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] :file_get_contents("php://input"); //3.2 處理數(shù)據(jù)包 $xmlObj = simplexml_load_string($postData, "SimpleXMLElement", LIBXML_NOCDATA); $msgType = $xmlObj->MsgType; //4 根據(jù)消息類型進行業(yè)務處理 switch ($msgType) { //接受事件消息 case 'event': $this->disposeEvent($xmlObj); break; //接受文本消息 case 'text': $this->disposeText($xmlObj); break; //接受圖片消息 case 'image': $this->disposeImage($xmlObj); break; } } //處理接收的事件消息 private function disposeEvent($xmlObj){ switch ($xmlObj->Event){ case 'subscribe'://訂閱事件 $this->sendText('歡迎您的訂閱'); break; case 'unsubscribe'://取消訂閱事件 $this->sendText('good-bye');//該消息用戶其實是看不到的,取消訂閱事件一般用來清除數(shù)據(jù)庫記錄 break; } } //處理接收的文本消息 private function disposeText($xmlObj){ $text=trim($xmlObj->Content); //包含關鍵字都不做處理 if (!( strstr($text,'違規(guī)') //這里對違規(guī)的關鍵字做排除,不予理睬 )){ switch ($text){ case '你好': $this->sendText($xmlObj,'Hi 我是開發(fā)者服務器'); break; case 'new': $newsArr=array( array( "title"=>"看到這條消息,你可以買彩票了", "description"=>"本公眾號有許多小彩蛋,歡迎您的探索。", "picUrl"=>"http://img.mp.itc.cn/upload/20170610/03d69e8df0524b8cb59fd16dc2fec989.jpg", "url"=>"http://www.baidu.com" ) ); $this->sendNews($xmlObj,$newsArr); break; default: $this->tuling123($xmlObj,trim($xmlObj->Content)); //圖靈機器人 } } } //處理接收的圖片消息 private function disposeImage($xmlObj){ //一般情況下,不會去處理用戶發(fā)送的圖片 $this->sendImage($xmlObj,$xmlObj->PicUrl,$xmlObj->MediaId); } //發(fā)送文本的方法 private function sendText($xmlObj,$content){ $replyTextMsg=" %s "; echo sprintf($replyTextMsg,$xmlObj->FromUserName,$xmlObj->ToUserName,time(),$content); } //發(fā)送圖片的方法 private function sendImage($xmlObj,$mediaId){ $replyImageMsg=" %s "; echo sprintf($replyImageMsg,$xmlObj->FromUserName,$xmlObj->ToUserName,time(),$mediaId); } //發(fā)送圖文的方法 private function sendNews($xmlObj,$newsArr){ $newsTplHead = " %s %s "; $newsTplBody = " <![CDATA[%s]]> "; $newsTplFoot = " %s "; $replyNewsMsg = sprintf($newsTplHead, $xmlObj->FromUserName, $xmlObj->ToUserName, time(),count($newsArr)); foreach($newsArr as $key => $value){ $replyNewsMsg .= sprintf($newsTplBody, $value['title'], $value['description'], $value['picUrl'], $value['url']); } $replyNewsMsg .= sprintf($newsTplFoot, 0); echo $replyNewsMsg; } public function tuling123($xmlObj,$message){//這是是使用圖靈機器人 $tuTonken='2d8aaa17141c443----xxx---fsa'; //請去圖靈網(wǎng)http://www.tuling123.com/自己申請一個tonken $tuUrl='http://www.tuling123.com/openapi/api?key='.$tuTonken.'&info='.$message.'&userid='.$xmlObj->FromUserName; $tuData='{ "key": "'.$tuTonken.'", "info": "'.$message.'", "userid": "'.$xmlObj->FromUserName.'" }'; $results = $this->htts_request($tuUrl,$tuData); // print_r($results); if ($results['code']==100000){ $text=$results['text']; $this->sendText($xmlObj,$text); }else{ $this->sendText($xmlObj,'有問題,請輸入“幫助”'); } } //https請求(get和post) private function htts_request($url,$data=array()){

運維服務服務器網(wǎng)絡設備日常巡檢報告_服務器運維_運維服務口號大全

//1 初始化curl $ch=curl_init(); //2 設置傳輸選項 curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);//把頁面以文件流的形式返回 if (!empty($data)) { curl_setopt($ch, CURLOPT_POST, true); //設置為 POST 請求 curl_setopt($ch, CURLOPT_POSTFIELDS, $data); //設置POST的請求數(shù)據(jù) } //3 執(zhí)行curl請求 $outopt=curl_exec($ch); $outoptArr=json_decode($outopt,true); //4 關閉curl curl_close($ch); return $outoptArr; } } ?>

    //網(wǎng)頁授權-base型
    public function snsapi_base($redirect_uri){
        //以下是測試賬號
        $appid="wxb4----xxx";//請在第一章第5小節(jié)的圖片中看
        $appsecret="21da56-----xxx";//請在第一章第5小節(jié)的圖片中看
        //準備scope
        $snsapi_base_url="https://open.weixin.qq.com/connect/oauth2/authorize?appid={$appid}&redirect_uri={$redirect_uri}&response_type=code&scope=SCOPE&state=123#wechat_redirect";
        $code=$_GET['code'];
        //獲取code
        if (!isset($code)){
            header("Location:{$snsapi_base_url}");
        }
        //獲取access_token
        $url="https://api.weixin.qq.com/sns/oauth2/access_token?appid={$appid}&secret={$appsecret}&code={$code}&grant_type=authorization_code";
        return $this->htts_request($url);
    }

上一篇:提升IT服務支持水平的IT外包服務公司所運用的措施

下一篇:pc外包 上班兩周被辭退,被開除后我緊急找了3份Offer

發(fā)表評論:

評論記錄:

未查詢到任何數(shù)據(jù)!

在線咨詢

點擊這里給我發(fā)消息 售前咨詢專員

點擊這里給我發(fā)消息 售后服務專員

在線咨詢

免費通話

24小時免費咨詢

請輸入您的聯(lián)系電話,座機請加區(qū)號

免費通話

微信掃一掃

微信聯(lián)系
返回頂部