php 위 챗 공중 호 개발 음악 정보

본 논문 의 사례 는 phop 위 챗 대중 번호 음악 정보의 구체 적 인 코드 를 공유 하여 여러분 께 참고 하 시기 바 랍 니 다.구체 적 인 내용 은 다음 과 같 습 니 다.
고 품질-HQMusicUrl저 품질-MusicUrl  

描述
핵심 코드 는 다음 과 같 습 니 다.

$textTpl = "<xml>
        <ToUserName><![CDATA[%s]]></ToUserName>
        <FromUserName><![CDATA[%s]]></FromUserName>
        <CreateTime>%s</CreateTime>
        <MsgType><![CDATA[music]]></MsgType>
        <Music>
          <Title><![CDATA[   ]]></Title>
          <Description><![CDATA[   ]]></Description>
          <MusicUrl><![CDATA[http://1.dq095.applinzi.com/   .mp3]]></MusicUrl>
          <HQMusicUrl><![CDATA[http://1.dq095.applinzi.com/   .mp3]]></HQMusicUrl>
        </Music>
        <FuncFlag>0</FuncFlag>
      </xml>";       



if(!empty( $keyword ))
 {           
  $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time);
  echo $resultStr;
 }else{
  echo "Input something...";
 }
index.php 코드 는 다음 과 같 습 니 다.

<?php
/**
* wechat php test
 */

//define your token
define("TOKEN", "weixin");
$wechatObj = new wechatCallbackapiTest();
$wechatObj->responseMsg();

class wechatCallbackapiTest
{
  public function valid()
  {
    $echoStr = $_GET["echostr"];

    //valid signature , option
    if($this->checkSignature()){
      echo $echoStr;
      exit;
    }
  }

  public function responseMsg()
  {
    //get post data, May be due to the different environments
    $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];

    //extract post data
    if (!empty($postStr)){

        $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
        $fromUsername = $postObj->FromUserName;
        $toUsername = $postObj->ToUserName;
        $keyword = trim($postObj->Content);
        $time = time();
        $textTpl = "<xml>
              <ToUserName><![CDATA[%s]]></ToUserName>
              <FromUserName><![CDATA[%s]]></FromUserName>
              <CreateTime>%s</CreateTime>
              <MsgType><![CDATA[music]]></MsgType>
               <Music>
               <Title><![CDATA[   ]]></Title>
               <Description><![CDATA[   ]]></Description>
               <MusicUrl><![CDATA[http://1.dq095.applinzi.com/   .mp3]]></MusicUrl>
               <HQMusicUrl><![CDATA[http://1.dq095.applinzi.com/   .mp3]]></HQMusicUrl>
               </Music>
              <FuncFlag>0</FuncFlag>
              </xml>";       



        if(!empty( $keyword ))
        {

          $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time);
          echo $resultStr;
        }else{
          echo "Input something...";
        }

    }else {
      echo "";
      exit;
    }
  }

  private function checkSignature()
  {
    $signature = $_GET["signature"];
    $timestamp = $_GET["timestamp"];
    $nonce = $_GET["nonce"];  

    $token = TOKEN;
    $tmpArr = array($token, $timestamp, $nonce);
    sort($tmpArr);
    $tmpStr = implode( $tmpArr );
    $tmpStr = sha1( $tmpStr );

    if( $tmpStr == $signature ){
      return true;
    }else{
      return false;
    }
  }
}

?>
이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기