微信公眾號生成新浪短網(wǎng)址的實現(xiàn)?針對這個問題,這篇文章詳細介紹了相對應(yīng)的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。
富蘊網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)公司,富蘊網(wǎng)站設(shè)計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗。已為富蘊上千多家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站建設(shè)公司要多少錢,請找那個售后服務(wù)好的富蘊做網(wǎng)站的公司定做!
<?php
define("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、打開基本配置

3、填寫上面代碼的url

關(guān)于微信公眾號生成新浪短網(wǎng)址的實現(xiàn)問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關(guān)知識。
分享文章:微信公眾號生成新浪短網(wǎng)址的實現(xiàn)
分享網(wǎng)址:http://jinyejixie.com/article10/ijjjdo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站、網(wǎng)站建設(shè)、面包屑導航、靜態(tài)網(wǎng)站、搜索引擎優(yōu)化、外貿(mào)網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)