iso端不自动播放音乐是个问题,我们可以通过微信的jssdk来解决
<?php header("Access-Control-Allow-Origin:*"); $appid = "appid"; $secret = "secret"; // 步骤1.生成签名的随机串 function nonceStr($length){ $str = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJK1NGJBQRSTUVWXYZ';//随即串,62个字符 $strlen = 62; while($length > $strlen){ $str .= $str; $strlen += 62; } $str = str_shuffle($str); return substr($str,0,$length); } // 步骤2.获取access_token $result = http_get('https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$appid.'&secret='.$secret); $json = json_decode($result,true); $access_token = $json['access_token']; function http_get($url){ $oCurl = curl_init(); if(stripos($url,"https://")!==FALSE){ curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($oCurl, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1 } curl_setopt($oCurl, CURLOPT_URL, $url); curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1 ); $sContent = curl_exec($oCurl); $aStatus = curl_getinfo($oCurl); curl_close($oCurl); if(intval($aStatus["http_code"])==200){ return $sContent; }else{ return false; } } // 步骤3.获取ticket $url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token=$access_token"; $res = json_decode ( http_get ( $url ) ); $ticket = $res->ticket; // 步骤4.生成wx.config需要的参数 $surl = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; $ws = getWxConfig( $ticket,$surl,time(),nonceStr(16) ); function getWxConfig($jsapiTicket,$url,$timestamp,$nonceStr) { $string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr×tamp=$timestamp&url=$url"; $signature = sha1 ( $string ); $WxConfig["appId"] = $appid; $WxConfig["nonceStr"] = $nonceStr; $WxConfig["timestamp"] = $timestamp; $WxConfig["url"] = $url; $WxConfig["signature"] = $signature; $WxConfig["rawString"] = $string; return $WxConfig; } ?> <!doctype html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport"> <meta content="yes" name="apple-mobile-web-app-capable"> <meta content="black" name="apple-mobile-web-app-status-bar-style"> </head> <script> <script src="http://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script> <script> // 配置接口成功 wx.config({ appId: '<?php echo $appid; ?>', timestamp: '<?php echo $ws["timestamp"]; ?>', nonceStr: '<?php echo $ws["nonceStr"]; ?>', signature: '<?php echo $ws["signature"]; ?>', jsApiList: [ // 必填,需要使用的JS接口列表 'playVoice', // 播放录音的接口 ] }); wx.ready(function() { document.getElementById('music1').play(); $('#music1').on('ended',function(){ document.getElementById('music1').play(); }) }); </script> </body> </html>
文章评论(0)