频道栏目
首页 > 程序开发 > Web开发 > PHP教程 > PHP开放平台 > 微信开发 > 正文
根据关键字返回音乐的微信公众号接口源码
2016-01-06 17:34:27      个评论      
收藏   我要投稿
根据关键字返回音乐的微信公众号接口源码,可以加一下我的微信号 lweixin-com 体验一下

源码如下:

/**
* wechat php test
*/

//define your token
//header("Content-Type: text/html;charset=utf-8");
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 song($$$$name){
$$$$content2 = file_get_contents("https://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


<![cdata[%s]]></![cdata[%s]]>




0

";
if(!empty( $$$$keyword ))
{
$$$$msgType = "music";
$$$$songname = iconv('utf-8','gb2312',$$$$keyword);
$$$$songnameurlcode = urlencode($$$$songname);
$$$$musicinfo = $$$$this->song($$$$songnameurlcode);
$$$$musicurl = 'https://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;
}
}
}

点击复制链接 与好友分享!回本站首页
上一篇:一个微信公众平台获取每日笑话返回给用户的接口
下一篇:微信公众平台教程:从入门到精通
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训

版权所有: 红黑联盟--致力于做实用的IT技术学习网站