/** * 处理微信支付异步通知 * @return array [是否支付成功, 异步通知的原始数据, 回复微信异步通知的数据] */ public function progressWxPayNotify() { // PHP7移除了HTTP_RAW_POST_DATA $xml = file_get_contents('php://input'); try { libxml_disable_entity_loader(true); $data = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true); if (!is_array($data)) { return [false, $data, ['return_code' => 'FAIL', 'return_msg' => '']]; } // 格式是否正确 if (!array_key_exists('return_code', $data)) { return [false, $data, ['return_code' => 'FAIL', 'return_msg' => 'return_code is not set']]; } // 是否支付成功 if ($data['return_code'] != 'SUCCESS') { return [false, $data, ['return_code' => 'FAIL', 'return_msg' => 'return_code is ' . $data['return_code']]]; } // 签名是否正确 $sign1 = SHA1::getSign2($data, 'key=' . $this->key); if ($sign1 != $data['sign']) { return [false, $data, ['return_code' => 'FAIL', 'return_msg' => '签名验证失败']]; } // 支付成功 return [true, $data, ['return_code' => 'SUCCESS', 'return_msg' => 'OK']]; } catch (\Exception $e) { return [false, [], ['return_code' => 'FAIL', 'return_msg' => $e->getMessage()]]; } }
/** * 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',