亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

 更新時(shí)間:2019年08月18日 09:36:28   作者:TANKING  
這篇文章主要介紹了微信公眾號(hào)生成新浪短網(wǎng)址的實(shí)現(xiàn)(快速生成),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

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

其實(shí)很簡(jiǎn)單:

<?php
define("TOKEN", "xiao");
//用于回復(fù)用戶消息
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 = "請(qǐng)發(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 "不對(duì)";
      exit;
  }
}

  $echoStr = $_GET["echostr"];
  //如果有$echoStr說明是對(duì)接
  if (!empty($echoStr)) {
    //對(duì)接規(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、登錄公眾號(hào)
2、打開基本配置

3、填寫上面代碼的url

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

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

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論