| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518 |
- <?php
- //decode by qq784939922
- require_once 'WxPay.Exception.php';
- require_once 'WxPay.Config.php';
- class Common_util_pub
- {
- function __construct()
- {
- }
- function trimString($_var_0)
- {
- $_var_1 = null;
- if (null != $_var_0) {
- $_var_1 = $_var_0;
- if (strlen($_var_1) == 0) {
- $_var_1 = null;
- }
- }
- return $_var_1;
- }
- public function createNoncestr($_var_2 = 32)
- {
- $_var_3 = 'abcdefghijklmnopqrstuvwxyz0123456789';
- $_var_4 = "";
- for ($_var_5 = 0; $_var_5 < $_var_2; $_var_5++) {
- $_var_4 .= substr($_var_3, mt_rand(0, strlen($_var_3) - 1), 1);
- }
- return $_var_4;
- }
- function formatBizQueryParaMap($_var_6, $_var_7)
- {
- $_var_8 = "";
- ksort($_var_6);
- foreach ($_var_6 as $_var_9 => $_var_10) {
- if ($_var_7) {
- $_var_10 = urlencode($_var_10);
- }
- $_var_8 .= $_var_9 . '=' . $_var_10 . '&';
- }
- $_var_11;
- if (strlen($_var_8) > 0) {
- $_var_11 = substr($_var_8, 0, strlen($_var_8) - 1);
- }
- return $_var_11;
- }
- public function getSign($_var_12)
- {
- foreach ($_var_12 as $_var_9 => $_var_10) {
- $_var_13[$_var_9] = $_var_10;
- }
- ksort($_var_13);
- $_var_14 = $this->formatBizQueryParaMap($_var_13, false);
- $_var_14 = $_var_14 . '&key=' . WxPayConfig::$KEY;
- $_var_14 = md5($_var_14);
- $_var_15 = strtoupper($_var_14);
- return $_var_15;
- }
- function arrayToXml($_var_16)
- {
- $_var_17 = '<xml>';
- foreach ($_var_16 as $_var_18 => $_var_19) {
- if (is_numeric($_var_19)) {
- $_var_17 .= '<' . $_var_18 . '>' . $_var_19 . '</' . $_var_18 . '>';
- } else {
- $_var_17 .= '<' . $_var_18 . '><![CDATA[' . $_var_19 . ']]></' . $_var_18 . '>';
- }
- }
- $_var_17 .= '</xml>';
- return $_var_17;
- }
- public function xmlToArray($_var_17)
- {
- $_var_20 = json_decode(json_encode(simplexml_load_string($_var_17, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
- return $_var_20;
- }
- public function postXmlCurl($_var_17, $_var_21, $_var_22 = 30)
- {
- $_var_23 = curl_init();
- curl_setopt($_var_23, CURLOPT_TIMEOUT, $_var_22);
- curl_setopt($_var_23, CURLOPT_URL, $_var_21);
- curl_setopt($_var_23, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($_var_23, CURLOPT_SSL_VERIFYHOST, FALSE);
- curl_setopt($_var_23, CURLOPT_HEADER, FALSE);
- curl_setopt($_var_23, CURLOPT_RETURNTRANSFER, TRUE);
- curl_setopt($_var_23, CURLOPT_POST, TRUE);
- curl_setopt($_var_23, CURLOPT_POSTFIELDS, $_var_17);
- $_var_24 = curl_exec($_var_23);
- curl_close($_var_23);
- if ($_var_24) {
- return $_var_24;
- } else {
- $_var_25 = curl_errno($_var_23);
- echo "curl出错,错误码:{$_var_25}" . '<br>';
- echo '<a href=\'http://curl.haxx.se/libcurl/c/libcurl-errors.html\'>错误原因查询</a></br>';
- curl_close($_var_23);
- return false;
- }
- }
- function postXmlSSLCurl($_var_17, $_var_21, $_var_22 = 30)
- {
- $_var_23 = curl_init();
- curl_setopt($_var_23, CURLOPT_TIMEOUT, $_var_22);
- curl_setopt($_var_23, CURLOPT_URL, $_var_21);
- curl_setopt($_var_23, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($_var_23, CURLOPT_SSL_VERIFYHOST, FALSE);
- curl_setopt($_var_23, CURLOPT_HEADER, FALSE);
- curl_setopt($_var_23, CURLOPT_RETURNTRANSFER, TRUE);
- curl_setopt($_var_23, CURLOPT_SSLCERTTYPE, 'PEM');
- curl_setopt($_var_23, CURLOPT_SSLCERT, WxPayConfig::SSLCERT_PATH);
- curl_setopt($_var_23, CURLOPT_SSLKEYTYPE, 'PEM');
- curl_setopt($_var_23, CURLOPT_SSLKEY, WxPayConfig::SSLKEY_PATH);
- curl_setopt($_var_23, CURLOPT_POST, true);
- curl_setopt($_var_23, CURLOPT_POSTFIELDS, $_var_17);
- $_var_24 = curl_exec($_var_23);
- if ($_var_24) {
- return $_var_24;
- } else {
- $_var_25 = curl_errno($_var_23);
- echo "curl出错,错误码:{$_var_25}" . '<br>';
- echo '<a href=\'http://curl.haxx.se/libcurl/c/libcurl-errors.html\'>错误原因查询</a></br>';
- curl_close($_var_23);
- return false;
- }
- }
- function printErr($_var_26 = '', $_var_27 = '')
- {
- print_r('<pre>');
- echo $_var_26 . '</br>';
- var_dump($_var_27);
- print_r('</pre>');
- }
- }
- class Wxpay_client_pub extends Common_util_pub
- {
- var $parameters;
- public $response;
- public $result;
- var $url;
- var $curl_timeout;
- function setParameter($_var_28, $_var_29)
- {
- $this->parameters[$this->trimString($_var_28)] = $this->trimString($_var_29);
- }
- function createXml()
- {
- $this->parameters['appid'] = WxPayConfig::$APPID;
- $this->parameters['mch_id'] = WxPayConfig::$MCHID;
- $this->parameters['nonce_str'] = $this->createNoncestr();
- $this->parameters['sign'] = $this->getSign($this->parameters);
- return $this->arrayToXml($this->parameters);
- }
- function postXml()
- {
- $_var_17 = $this->createXml();
- $this->response = $this->postXmlCurl($_var_17, $this->url, $this->curl_timeout);
- return $this->response;
- }
- function postXmlSSL()
- {
- $_var_17 = $this->createXml();
- $this->response = $this->postXmlSSLCurl($_var_17, $this->url, $this->curl_timeout);
- return $this->response;
- }
- function getResult()
- {
- $this->postXml();
- $this->result = $this->xmlToArray($this->response);
- return $this->result;
- }
- }
- class UnifiedOrder_pub extends Wxpay_client_pub
- {
- function __construct()
- {
- $this->url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
- $this->curl_timeout = WxPayConfig::$CURL_TIMEOUT;
- }
- function createXml()
- {
- try {
- if ($this->parameters['out_trade_no'] == null) {
- throw new WxPayException('缺少统一支付接口必填参数out_trade_no!' . '<br>');
- } elseif ($this->parameters['body'] == null) {
- throw new WxPayException('缺少统一支付接口必填参数body!' . '<br>');
- } elseif ($this->parameters['total_fee'] == null) {
- throw new WxPayException('缺少统一支付接口必填参数total_fee!' . '<br>');
- } elseif ($this->parameters['notify_url'] == null) {
- throw new WxPayException('缺少统一支付接口必填参数notify_url!' . '<br>');
- } elseif ($this->parameters['trade_type'] == null) {
- throw new WxPayException('缺少统一支付接口必填参数trade_type!' . '<br>');
- } elseif ($this->parameters['trade_type'] == 'JSAPI' && $this->parameters['openid'] == NULL) {
- throw new WxPayException('统一支付接口中,缺少必填参数openid!trade_type为JSAPI时,openid为必填参数!' . '<br>');
- }
- $this->parameters['appid'] = WxPayConfig::$APPID;
- $this->parameters['mch_id'] = WxPayConfig::$MCHID;
- $this->parameters['spbill_create_ip'] = $_SERVER['REMOTE_ADDR'];
- $this->parameters['nonce_str'] = $this->createNoncestr();
- $this->parameters['sign'] = $this->getSign($this->parameters);
- return $this->arrayToXml($this->parameters);
- } catch (WxPayException $_var_30) {
- die($_var_30->errorMessage());
- }
- }
- function getPrepayId()
- {
- $this->postXml();
- $this->result = $this->xmlToArray($this->response);
- $_var_31 = $this->result['prepay_id'];
- return $_var_31;
- }
- }
- class OrderQuery_pub extends Wxpay_client_pub
- {
- function __construct()
- {
- $this->url = 'https://api.mch.weixin.qq.com/pay/orderquery';
- $this->curl_timeout = WxPayConfig::$CURL_TIMEOUT;
- }
- function createXml()
- {
- try {
- if ($this->parameters['out_trade_no'] == null && $this->parameters['transaction_id'] == null) {
- throw new WxPayException('订单查询接口中,out_trade_no、transaction_id至少填一个!' . '<br>');
- }
- $this->parameters['appid'] = WxPayConfig::$APPID;
- $this->parameters['mch_id'] = WxPayConfig::$MCHID;
- $this->parameters['nonce_str'] = $this->createNoncestr();
- $this->parameters['sign'] = $this->getSign($this->parameters);
- return $this->arrayToXml($this->parameters);
- } catch (WxPayException $_var_30) {
- die($_var_30->errorMessage());
- }
- }
- }
- class Refund_pub extends Wxpay_client_pub
- {
- function __construct()
- {
- $this->url = 'https://api.mch.weixin.qq.com/secapi/pay/refund';
- $this->curl_timeout = WxPayConfig::$CURL_TIMEOUT;
- }
- function createXml()
- {
- try {
- if ($this->parameters['out_trade_no'] == null && $this->parameters['transaction_id'] == null) {
- throw new WxPayException('退款申请接口中,out_trade_no、transaction_id至少填一个!' . '<br>');
- } elseif ($this->parameters['out_refund_no'] == null) {
- throw new WxPayException('退款申请接口中,缺少必填参数out_refund_no!' . '<br>');
- } elseif ($this->parameters['total_fee'] == null) {
- throw new WxPayException('退款申请接口中,缺少必填参数total_fee!' . '<br>');
- } elseif ($this->parameters['refund_fee'] == null) {
- throw new WxPayException('退款申请接口中,缺少必填参数refund_fee!' . '<br>');
- } elseif ($this->parameters['op_user_id'] == null) {
- throw new WxPayException('退款申请接口中,缺少必填参数op_user_id!' . '<br>');
- }
- $this->parameters['appid'] = WxPayConfig::$APPID;
- $this->parameters['mch_id'] = WxPayConfig::$MCHID;
- $this->parameters['nonce_str'] = $this->createNoncestr();
- $this->parameters['sign'] = $this->getSign($this->parameters);
- return $this->arrayToXml($this->parameters);
- } catch (WxPayException $_var_30) {
- die($_var_30->errorMessage());
- }
- }
- function getResult()
- {
- $this->postXmlSSL();
- $this->result = $this->xmlToArray($this->response);
- return $this->result;
- }
- }
- class RefundQuery_pub extends Wxpay_client_pub
- {
- function __construct()
- {
- $this->url = 'https://api.mch.weixin.qq.com/pay/refundquery';
- $this->curl_timeout = WxPayConfig::$CURL_TIMEOUT;
- }
- function createXml()
- {
- try {
- if ($this->parameters['out_refund_no'] == null && $this->parameters['out_trade_no'] == null && $this->parameters['transaction_id'] == null && $this->parameters['refund_id '] == null) {
- throw new WxPayException('退款查询接口中,out_refund_no、out_trade_no、transaction_id、refund_id四个参数必填一个!' . '<br>');
- }
- $this->parameters['appid'] = WxPayConfig::$APPID;
- $this->parameters['mch_id'] = WxPayConfig::$MCHID;
- $this->parameters['nonce_str'] = $this->createNoncestr();
- $this->parameters['sign'] = $this->getSign($this->parameters);
- return $this->arrayToXml($this->parameters);
- } catch (WxPayException $_var_30) {
- die($_var_30->errorMessage());
- }
- }
- function getResult()
- {
- $this->postXmlSSL();
- $this->result = $this->xmlToArray($this->response);
- return $this->result;
- }
- }
- class DownloadBill_pub extends Wxpay_client_pub
- {
- function __construct()
- {
- $this->url = 'https://api.mch.weixin.qq.com/pay/downloadbill';
- $this->curl_timeout = WxPayConfig::$CURL_TIMEOUT;
- }
- function createXml()
- {
- try {
- if ($this->parameters['bill_date'] == null) {
- throw new WxPayException('对账单接口中,缺少必填参数bill_date!' . '<br>');
- }
- $this->parameters['appid'] = WxPayConfig::$APPID;
- $this->parameters['mch_id'] = WxPayConfig::$MCHID;
- $this->parameters['nonce_str'] = $this->createNoncestr();
- $this->parameters['sign'] = $this->getSign($this->parameters);
- return $this->arrayToXml($this->parameters);
- } catch (WxPayException $_var_30) {
- die($_var_30->errorMessage());
- }
- }
- function getResult()
- {
- $this->postXml();
- $this->result = $this->xmlToArray($this->result_xml);
- return $this->result;
- }
- }
- class ShortUrl_pub extends Wxpay_client_pub
- {
- function __construct()
- {
- $this->url = 'https://api.mch.weixin.qq.com/tools/shorturl';
- $this->curl_timeout = WxPayConfig::$CURL_TIMEOUT;
- }
- function createXml()
- {
- try {
- if ($this->parameters['long_url'] == null) {
- throw new WxPayException('短链接转换接口中,缺少必填参数long_url!' . '<br>');
- }
- $this->parameters['appid'] = WxPayConfig::$APPID;
- $this->parameters['mch_id'] = WxPayConfig::$MCHID;
- $this->parameters['nonce_str'] = $this->createNoncestr();
- $this->parameters['sign'] = $this->getSign($this->parameters);
- return $this->arrayToXml($this->parameters);
- } catch (WxPayException $_var_30) {
- die($_var_30->errorMessage());
- }
- }
- function getShortUrl()
- {
- $this->postXml();
- $_var_31 = $this->result['short_url'];
- return $_var_31;
- }
- }
- class Wxpay_server_pub extends Common_util_pub
- {
- public $data;
- var $returnParameters;
- function saveData($_var_17)
- {
- $this->data = $this->xmlToArray($_var_17);
- }
- function checkSign()
- {
- $_var_32 = $this->data;
- unset($_var_32['sign']);
- $_var_33 = $this->getSign($_var_32);
- if ($this->data['sign'] == $_var_33) {
- return TRUE;
- }
- return FALSE;
- }
- function getData()
- {
- return $this->data;
- }
- function setReturnParameter($_var_28, $_var_29)
- {
- $this->returnParameters[$this->trimString($_var_28)] = $this->trimString($_var_29);
- }
- function createXml()
- {
- return $this->arrayToXml($this->returnParameters);
- }
- function returnXml()
- {
- $_var_34 = $this->createXml();
- return $_var_34;
- }
- }
- class Notify_pub extends Wxpay_server_pub
- {
- }
- class NativeCall_pub extends Wxpay_server_pub
- {
- function createXml()
- {
- if ($this->returnParameters['return_code'] == 'SUCCESS') {
- $this->returnParameters['appid'] = WxPayConfig::$APPID;
- $this->returnParameters['mch_id'] = WxPayConfig::$MCHID;
- $this->returnParameters['nonce_str'] = $this->createNoncestr();
- $this->returnParameters['sign'] = $this->getSign($this->returnParameters);
- }
- return $this->arrayToXml($this->returnParameters);
- }
- function getProductId()
- {
- $_var_35 = $this->data['product_id'];
- return $_var_35;
- }
- }
- class NativeLink_pub extends Common_util_pub
- {
- var $parameters;
- var $url;
- function __construct()
- {
- }
- function setParameter($_var_28, $_var_29)
- {
- $this->parameters[$this->trimString($_var_28)] = $this->trimString($_var_29);
- }
- function createLink()
- {
- try {
- if ($this->parameters['product_id'] == null) {
- throw new WxPayException('缺少Native支付二维码链接必填参数product_id!' . '<br>');
- }
- $this->parameters['appid'] = WxPayConfig::$APPID;
- $this->parameters['mch_id'] = WxPayConfig::$MCHID;
- $_var_36 = time();
- $this->parameters['time_stamp'] = "{$_var_36}";
- $this->parameters['nonce_str'] = $this->createNoncestr();
- $this->parameters['sign'] = $this->getSign($this->parameters);
- $_var_37 = $this->formatBizQueryParaMap($this->parameters, false);
- $this->url = 'weixin://wxpay/bizpayurl?' . $_var_37;
- } catch (WxPayException $_var_30) {
- die($_var_30->errorMessage());
- }
- }
- function getUrl()
- {
- $this->createLink();
- return $this->url;
- }
- }
- class JsApi_pub extends Common_util_pub
- {
- var $code;
- var $openid;
- var $parameters;
- var $prepay_id;
- var $curl_timeout;
- function __construct()
- {
- $this->curl_timeout = WxPayConfig::$CURL_TIMEOUT;
- }
- function createOauthUrlForCode($_var_38)
- {
- $_var_39['appid'] = WxPayConfig::$APPID;
- $_var_39['redirect_uri'] = "{$_var_38}";
- $_var_39['response_type'] = 'code';
- $_var_39['scope'] = 'snsapi_base';
- $_var_39['state'] = 'STATE' . '#wechat_redirect';
- $_var_37 = $this->formatBizQueryParaMap($_var_39, false);
- return 'https://open.weixin.qq.com/connect/oauth2/authorize?' . $_var_37;
- }
- function createOauthUrlForOpenid()
- {
- $_var_39['appid'] = WxPayConfig::$APPID;
- $_var_39['secret'] = WxPayConfig::$APPSECRET;
- $_var_39['code'] = $this->code;
- $_var_39['grant_type'] = 'authorization_code';
- $_var_37 = $this->formatBizQueryParaMap($_var_39, false);
- return 'https://api.weixin.qq.com/sns/oauth2/access_token?' . $_var_37;
- }
- function getOpenid()
- {
- $_var_21 = $this->createOauthUrlForOpenid();
- $_var_23 = curl_init();
- curl_setopt($_var_23, CURLOP_TIMEOUT, $this->curl_timeout);
- curl_setopt($_var_23, CURLOPT_URL, $_var_21);
- curl_setopt($_var_23, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($_var_23, CURLOPT_SSL_VERIFYHOST, FALSE);
- curl_setopt($_var_23, CURLOPT_HEADER, FALSE);
- curl_setopt($_var_23, CURLOPT_RETURNTRANSFER, TRUE);
- $_var_40 = curl_exec($_var_23);
- curl_close($_var_23);
- $_var_24 = json_decode($_var_40, true);
- $this->openid = $_var_24['openid'];
- return $this->openid;
- }
- function setPrepayId($_var_41)
- {
- $this->prepay_id = $_var_41;
- }
- function setCode($_var_42)
- {
- $this->code = $_var_42;
- }
- public function getParameters()
- {
- $_var_43['appId'] = WxPayConfig::$APPID;
- $_var_44 = time();
- $_var_43['timeStamp'] = "{$_var_44}";
- $_var_43['nonceStr'] = $this->createNoncestr();
- $_var_43['package'] = "prepay_id={$this->prepay_id}";
- $_var_43['signType'] = 'MD5';
- $_var_43['paySign'] = $this->getSign($_var_43);
- $this->parameters = json_encode($_var_43);
- return $this->parameters;
- }
- }
|