首页 > PHP资讯 > 工具库 > 根据关键字返回音乐的微信公众号接口源码

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

工具库
根据关键字返回音乐的微信公众号接口源码,可以加一下我的微信号 lweixin-com 体验一下

源码如下:
  1. /**
  2. * wechat php test
  3. */

  4. //define your token
  5. //header("Content-Type: text/html;charset=utf-8");
  6. define("TOKEN", "weixin");
  7. $$$$wechatObj = new wechatCallbackapiTest();
  8. $$$$wechatObj->responseMsg();


  9. class wechatCallbackapiTest
  10. {
  11. public function valid()
  12. {
  13. $$$$echoStr = $$$$_GET["echostr"];

  14. //valid signature , option
  15. if($$$$this->checkSignature()){
  16. echo $$$$echoStr;
  17. exit;
  18. }
  19. }
  20. public function song($$$$name){
  21. $$$$content2 = file_get_contents("http://shopcgi.qqmusic.qq.com/fcgi-bin/shopsearch.fcg?value=".$$$$name);
  22. $$$$str2=substr($$$$content2,15);
  23. $$$$str2=substr($$$$str2,0,-2);
  24. $$$$tempstrs = explode(",",$$$$str2);
  25. $$$$endstr = array();
  26. $$$$i=0;

  27. foreach($$$$tempstrs as $$$$tempstr)
  28. {
  29. $$$$endstr[$$$$i] = str_replace(":",'":',$$$$tempstr);
  30. if($$$$i != 0)
  31. {
  32. $$$$endstr[$$$$i] = '"'.$$$$endstr[$$$$i];
  33. }
  34. $$$$i++;
  35. }
  36. $$$$endstr[0] = str_replace('{','{"',$$$$endstr[0]);
  37. $$$$endstr[5] = str_replace('[{','[{"',$$$$endstr[5]);
  38. $$$$str2 = implode(",",$$$$endstr);
  39. $$$$str2 = str_replace("[","",$$$$str2);
  40. $$$$str2 = str_replace("]","",$$$$str2);
  41. $$$$str2 = str_replace(""{","{"",$$$$str2);
  42. $$$$tempstrs = explode(",",$$$$str2);
  43. $$$$tempstrs[5] = '"songlist1":{"idx":"1"';
  44. $$$$i=0;
  45. $$$$x=2;
  46. foreach($$$$tempstrs as $$$$json){
  47. $$$$jsons[$$$$i] = iconv('gb2312', 'utf-8//IGNORE', $$$$json);
  48. if(substr($$$$json,0,8)=='{"idx":"'){
  49. $$$$a = $$$$i-1;
  50. $$$$jsons[$$$$i] = iconv('gb2312', 'utf-8//IGNORE', '"songlist'.$$$$x.'":{"idx":"'.$$$$x.'"');
  51. $$$$x++;
  52. }
  53. $$$$i++;
  54. }
  55. $$$$str = implode(",",$$$$jsons);
  56. $$$$result=json_decode($$$$str,true);
  57. return $$$$result;
  58. }
  59. public function responseMsg()
  60. {
  61. //get post data, May be due to the different environments
  62. @$$$$postStr = $$$$GLOBALS["HTTP_RAW_POST_DATA"];

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

  65. $$$$postObj = simplexml_load_string($$$$postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
  66. $$$$fromUsername = $$$$postObj->FromUserName;
  67. $$$$toUsername = $$$$postObj->ToUserName;
  68. $$$$keyword = trim($$$$postObj->Content);
  69. $$$$time = time();
  70. $$$$textTpl = "



  71. %s


  72. <![CDATA[%s]]>




  73. 0
  74. ";
  75. if(!empty( $$$$keyword ))
  76. {
  77. $$$$msgType = "music";
  78. $$$$songname = iconv('utf-8','gb2312',$$$$keyword);
  79. $$$$songnameurlcode = urlencode($$$$songname);
  80. $$$$musicinfo = $$$$this->song($$$$songnameurlcode);
  81. $$$$musicurl = 'http://stream1'.$$$$musicinfo[songlist1][location].".qqmusic.qq.com/3".$$$$musicinfo[songlist1][song_id].".mp3";
  82. $$$$resultStr = sprintf($$$$textTpl, $$$$fromUsername, $$$$toUsername, $$$$time, $$$$msgType, $$$$musicinfo[songlist1][song_name],"歌手:".$$$$musicinfo[songlist1][singer_name]." 专辑:".$$$$musicinfo[songlist1][album_name],$$$$musicurl,$$$$musicurl);
  83. echo $$$$resultStr;
  84. }else{
  85. echo "Input something...";
  86. }

  87. }else {
  88. echo "";
  89. exit;
  90. }
  91. }

  92. private function checkSignature()
  93. {
  94. $$$$signature = $$$$_GET["signature"];
  95. $$$$timestamp = $$$$_GET["timestamp"];
  96. $$$$nonce = $$$$_GET["nonce"];

  97. $$$$token = TOKEN;
  98. $$$$tmpArr = array($$$$token, $$$$timestamp, $$$$nonce);
  99. sort($$$$tmpArr);
  100. $$$$tmpStr = implode( $$$$tmpArr );
  101. $$$$tmpStr = sha1( $$$$tmpStr );

  102. if( $$$$tmpStr == $$$$signature ){
  103. return true;
  104. }else{
  105. return false;
  106. }
  107. }
  108. }

工具库

本文由欣才IT学院整理发布,未经许可,禁止转载。
支持20不支持0