设为首页收藏本站
查看: 86|回复: 0

[PHP] 根据关键字返回音乐的微信公众号接口源码

[复制链接]

论坛元老

Rank: 6Rank: 6

积分
34274
主题
17031
UID
1347
M币
67
贡献
17176

  • 发表于 2013-6-23 23:53:00 | 显示全部楼层 |阅读模式
    根据关键字返回音乐的微信公众号接口源码,可以加一下我的微信号 lweixin-com 体验一下

    源码如下:   [ol]
  • responseMsg();


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

  • //valid signature , option
  • if($$$$this->checkSignature()){
  • echo $$$$echoStr;
  • exit;
  • }
  • }
  • public function song($$$$name){
  • $$$$content2 = file_get_contents("http://shopcgi.qqmusic.qq.com/fcgi-bin/shopsearch.fcg?value=".$$$$name);
  • $$$$str2=substr($$$$content2,15);
  • $$$$str2=substr($$$$str2,0,-2);
  • $$$$tempstrs = explode(",",$$$$str2);
  • $$$$endstr = array();
  • $$$$i=0;

  • foreach($$$$tempstrs as $$$$tempstr)
  • {
  • $$$$endstr[$$$$i] = str_replace(":",'":',$$$$tempstr);
  • if($$$$i != 0)
  • {
  • $$$$endstr[$$$$i] = '"'.$$$$endstr[$$$$i];
  • }
  • $$$$i++;
  • }
  • $$$$endstr[0] = str_replace('{','{"',$$$$endstr[0]);
  • $$$$endstr[5] = str_replace('[{','[{"',$$$$endstr[5]);
  • $$$$str2 = implode(",",$$$$endstr);
  • $$$$str2 = str_replace("[","",$$$$str2);
  • $$$$str2 = str_replace("]","",$$$$str2);
  • $$$$str2 = str_replace("\"{","{\"",$$$$str2);
  • $$$$tempstrs = explode(",",$$$$str2);
  • $$$$tempstrs[5] = '"songlist1":{"idx":"1"';
  • $$$$i=0;
  • $$$$x=2;
  • foreach($$$$tempstrs as $$$$json){
  • $$$$jsons[$$$$i] = iconv('gb2312', 'utf-8//IGNORE', $$$$json);
  • if(substr($$$$json,0,8)=='{"idx":"'){
  • $$$$a = $$$$i-1;
  • $$$$jsons[$$$$i] = iconv('gb2312', 'utf-8//IGNORE', '"songlist'.$$$$x.'":{"idx":"'.$$$$x.'"');
  • $$$$x++;
  • }
  • $$$$i++;
  • }
  • $$$$str = implode(",",$$$$jsons);
  • $$$$result=json_decode($$$$str,true);
  • return $$$$result;
  • }
  • 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 = "



  • %s







  • 0
  • ";
  • if(!empty( $$$$keyword ))
  • {
  • $$$$msgType = "music";
  • $$$$sOngname= iconv('utf-8','gb2312',$$$$keyword);
  • $$$$sOngnameurlcode= urlencode($$$$songname);
  • $$$$musicinfo = $$$$this->song($$$$songnameurlcode);
  • $$$$musicurl = 'http://stream1'.$$$$musicinfo[songlist1][location].".qqmusic.qq.com/3".$$$$musicinfo[songlist1][song_id].".mp3";
  • $$$$resultStr = sprintf($$$$textTpl, $$$$fromUsername, $$$$toUsername, $$$$time, $$$$msgType, $$$$musicinfo[songlist1][song_name],"歌手:".$$$$musicinfo[songlist1][singer_name]." 专辑:".$$$$musicinfo[songlist1][album_name],$$$$musicurl,$$$$musicurl);
  • 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;
  • }
  • }
  • }

  •   [/ol]
  • 回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    在我站开通SVIP可同时获得17个站点VIP资源 立即登录 立即注册
    快速回复 返回顶部 返回列表