国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > JS > 正文

微信公眾號生成新浪短網(wǎng)址的實現(xiàn)(快速生成)

2024-05-06 16:54:19
字體:
供稿:網(wǎng)友

有沒有想過,向一個公眾號發(fā)送長鏈接,然后公眾號給你回復一個短網(wǎng)址?

其實很簡單:

微信公眾號,新浪,短網(wǎng)址

<?phpdefine("TOKEN", "xiao");//用于回復用戶消息function responseMsg(){  $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];  if (!empty($postStr)){    $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);    $fromUsername = $postObj->FromUserName;    $toUsername = $postObj->ToUserName;    $MsgT = $postObj->MsgType;    $time = time();    //如果用戶發(fā)的text類型    if($MsgT=="text"){      $key = trim($postObj->Content);      $textTpl = "<xml>            <ToUserName><![CDATA[%s]]></ToUserName>            <FromUserName><![CDATA[%s]]></FromUserName>            <CreateTime>%s</CreateTime>            <MsgType><![CDATA[%s]]></MsgType>            <Content><![CDATA[%s]]></Content>            </xml>";       $msgType = "text";      //生成短網(wǎng)址      $dwzapi = "http://api.t.sina.com.cn/short_url/shorten.json?source=3271760578&url_long=".$key;      $dwzpost = file_get_contents($dwzapi);      $dwzjsondecode = json_decode($dwzpost,true);      //發(fā)送      $contentStr = $dwzjsondecode[0]['url_short'];            $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);      echo $resultStr;      exit;    }else{      $textTpl = "<xml>            <ToUserName><![CDATA[%s]]></ToUserName>            <FromUserName><![CDATA[%s]]></FromUserName>            <CreateTime>%s</CreateTime>            <MsgType><![CDATA[%s]]></MsgType>            <Content><![CDATA[%s]]></Content>            </xml>";       $msgType = "text";          //發(fā)送      $contentStr = "請發(fā)送鏈接";            $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);      echo $resultStr;      exit;    }    //如果用戶發(fā)的event(事件)類型    if($MsgT=="event"){      $Event = $postObj->Event;      if ($Event==subscribe) {        $contentStr = "歡迎關(guān)注";      }else{        $contentStr = "希望您下次關(guān)注,但您收不到此條消息了";      }      $textTpl = "<xml>            <ToUserName><![CDATA[%s]]></ToUserName>            <FromUserName><![CDATA[%s]]></FromUserName>            <CreateTime>%s</CreateTime>            <MsgType><![CDATA[%s]]></MsgType>            <Content><![CDATA[%s]]></Content>            </xml>";       $Title = $postObj->Title;      $Description = $postObj->Description;      $Url = $postObj->Url;      $msgType = 'text';      $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);      echo $resultStr;      exit;    }  }else{      echo "不對";      exit;  }}  $echoStr = $_GET["echostr"];  //如果有$echoStr說明是對接  if (!empty($echoStr)) {    //對接規(guī)則    $signature = $_GET["signature"];    $timestamp = $_GET["timestamp"];    $nonce = $_GET["nonce"];    $token = TOKEN;    $tmpArr = array($token, $timestamp, $nonce);    sort($tmpArr, SORT_STRING);    $tmpStr = implode( $tmpArr );    $tmpStr = sha1( $tmpStr );    if( $tmpStr == $signature ){      echo $echoStr;    }else{      echo "";      exit;    }  }else{    responseMsg();  }?>

配置方法:

1、登錄公眾號
2、打開基本配置

微信公眾號,新浪,短網(wǎng)址

3、填寫上面代碼的url

微信公眾號,新浪,短網(wǎng)址

Token在代碼里面自己設(shè)置,要對應的,EncodingAESKey隨機生成。

4、然后啟用這個配置,然后去公眾號發(fā)送一個url看看!

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持VeVb武林網(wǎng)。


注:相關(guān)教程知識閱讀請移步到JavaScript/Ajax教程頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 瓦房店市| 新昌县| 泸水县| 开封县| 腾冲县| 右玉县| 合川市| 达日县| 浠水县| 新疆| 永新县| 白玉县| 雅安市| 奉节县| 剑阁县| 成都市| 博罗县| 额济纳旗| 南木林县| 洞口县| 科技| 盐源县| 临泽县| 浙江省| 汉源县| 青神县| 大连市| 吉安县| 通海县| 财经| 凯里市| 武城县| 景德镇市| 遂昌县| 玉环县| 津南区| 南丹县| 神木县| 宁津县| 麻江县| 富川|