/** * JS-SDK 获取JS-SDK配置需要的信息 * * @param string $url 可选:调取JS-SDK的页面url,默认为HTTP_REFERER * @param string $type 可选:返回配置信息的格式 json & jsonp, 默认为对象数组 * @param string $$jsonp_callback 可选:使用json的callback名称 * * @return mixed * * Examples: * ``` * $api->get_jsapi_config(); * $api->get_jsapi_config('http://www.baidu.com/'); * ``` * Result: * ``` * { * errcode: 0, * appId: "wx733d7f24bd29224a", * timestamp: 1440073485, * nonceStr: "5Ars5fLaLuPEXSgm", * signature: "7f830aff99ff11fa931cae61b5b932b1f2c8ee10", * url: "http://www.baidu.com/" * } * ``` * * Examples: * ``` * $api->get_jsapi_config('', 'json'); * ``` * Result: * ``` * {"errcode":0,"appId":"wx733d7f24bd29224a","timestamp":1440073708,"nonceStr":"caFkkXnOhVrcq3Ke","signature":"1c6c08ddf6e0e3c0fd33aafcb160a9f67d6b8f94","url":null} * ``` * * Examples: * ``` * $api->get_jsapi_config('', 'jsonp'); * $api->get_jsapi_config('', 'jsonp', 'callback'); * ``` * Result: * ``` * ;jQuery17105012127514928579_1440073858610({"errcode":0,"appId":"wx733d7f24bd29224a","timestamp":1440073875,"nonceStr":"vsGBSM0MMiWeIJFQ","signature":"616005786e404fe0da226a6decc2730624bedbfc","url":null}) * ``` */ public function get_jsapi_config($url = '', $type = '', $jsonp_callback = 'callback') { $jsapi_ticket = $this->get_jsapi_ticket(); $nonce_str = SHA1::get_random_str(); $timestamp = time(); if ($url == '') { $url = $_SERVER['HTTP_REFERER']; } $signature = SHA1::get_jsapi_signature($jsapi_ticket, $nonce_str, $timestamp, $url); if ($signature === false) { $jsapi_config = array('errcode' => -1, 'errmsg' => 'get jsapi signature error.'); } else { $jsapi_config = array('errcode' => 0, 'appId' => $this->appId, 'timestamp' => $timestamp, 'nonceStr' => $nonce_str, 'signature' => $signature, 'url' => $url); } if ($type == 'json' || $type == 'jsonp') { $jsapi_config = json_encode($jsapi_config); if ($type == 'jsonp' && isset($_REQUEST[$jsonp_callback]) && !empty($_REQUEST[$jsonp_callback])) { $jsapi_config = ';' . $_REQUEST[$jsonp_callback] . '(' . $jsapi_config . ')'; } } return $jsapi_config; }
* 'media_id' => 'rVT43tfDwjh4p1BV2gJ5D7Zl2BswChO5L_llmlphLaTPytcGcguBAEJ1qK4cg4r_' * )); * ``` */ /** * 3 回复语音消息 * * Examples: * ``` * $wechat->reply(array( * 'type' => 'voice', * 'media_id' => 'rVT43tfDwjh4p1BV2gJ5D7Zl2BswChO5L_llmlphLaTPytcGcguBAEJ1qK4cg4r_' * )); * ``` */ case 'voice': $xml = sprintf('<xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%s</CreateTime> <MsgType><![CDATA[voice]]></MsgType> <Voice> <MediaId><![CDATA[%s]]></MediaId> </Voice> </xml>', $this->message->FromUserName, $this->message->ToUserName, time(), $msg['media_id']); break; /** * 4 回复视频消息 * * Examples: * ``` * $wechat->reply(array( * 'type' => 'video', * 'media_id' => 'yV0l71NL0wtpRA8OMX0-dBRQsMVyt3fspPUzurIS3psi6eWOrb_WlEeO39jasoZ8', * 'title' => '视频消息的标题', //可选 * 'description' => '视频消息的描述' //可选 * )); * ``` */ /** * 4 回复视频消息 * * Examples: * ``` * $wechat->reply(array( * 'type' => 'video', * 'media_id' => 'yV0l71NL0wtpRA8OMX0-dBRQsMVyt3fspPUzurIS3psi6eWOrb_WlEeO39jasoZ8',