├── src ├── Foundation │ ├── ServiceProvider.php │ ├── Request.php │ ├── Response.php │ ├── PaymentComm.php │ └── Foundation.php ├── AliPay │ ├── AliPayComm.php │ ├── AliPayRequest.php │ ├── AliPayResponse.php │ ├── Pos │ │ └── Pos.php │ ├── Web │ │ └── Web.php │ ├── JSApi │ │ └── JSApi.php │ ├── Qr │ │ └── Qr.php │ └── App │ │ └── App.php └── WeChat │ ├── WeChatComm.php │ ├── WeChatRequest.php │ ├── WeChatResponse.php │ ├── JSApi │ └── JSApi.php │ ├── Pos │ └── Pos.php │ ├── App │ └── App.php │ ├── H5 │ └── H5.php │ └── Native │ └── Native.php ├── composer.json ├── .gitignore ├── README.md ├── LICENSE └── composer.lock /src/Foundation/ServiceProvider.php: -------------------------------------------------------------------------------- 1 | 10 | */ 11 | interface Request 12 | { 13 | public function isSuccessful(); 14 | 15 | public function getRequestData(); 16 | 17 | } -------------------------------------------------------------------------------- /src/Foundation/Response.php: -------------------------------------------------------------------------------- 1 | 10 | */ 11 | interface Response 12 | { 13 | public function isSuccessful(); 14 | 15 | public function getRequestData(); 16 | 17 | public function getResponseData(); 18 | 19 | } -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fantasystudio/easypay", 3 | "description": "Wechat and Alipay payment SDK", 4 | "keywords": ["weixin", "wechat", "alipay"], 5 | "license": "Apache-2.0", 6 | "authors": [ 7 | { 8 | "name": "AndyLee", 9 | "email": "leefongyun@gmail.com", 10 | "role": "Developer" 11 | } 12 | ], 13 | "type": "library", 14 | "require": { 15 | "php": ">=5.5.0", 16 | "guzzlehttp/guzzle": "~6.2" 17 | }, 18 | "autoload": { 19 | "psr-4": { 20 | "FantasyStudio\\EasyPay\\": "src/" 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Foundation/PaymentComm.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | interface PaymentComm 11 | { 12 | 13 | /** 14 | * 设置支付参数 15 | * @param array $order 订单信息 16 | * @return mixed 17 | */ 18 | public function purchase($order); 19 | 20 | /** 21 | * 发起支付请求 22 | * @return mixed 23 | */ 24 | public function sendPaymentRequest(); 25 | 26 | // /** 27 | // * 处理异步通知 28 | // * @return mixed 29 | // */ 30 | // public function processNotifyRequest(); 31 | 32 | /** 33 | * 查询订单 34 | * @param array $data 35 | * @return mixed 36 | */ 37 | public function queryOrderState($data); 38 | 39 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # Intellij 36 | *.iml 37 | .idea/workspace.xml 38 | .idea/tasks.xml 39 | .idea/gradle.xml 40 | .idea/dictionaries 41 | .idea/libraries 42 | .idea/ 43 | # Keystore files 44 | *.jks 45 | 46 | # External native build folder generated in Android Studio 2.2 and later 47 | .externalNativeBuild 48 | 49 | # Google Services (e.g. APIs or Firebase) 50 | google-services.json 51 | 52 | # Freeline 53 | freeline.py 54 | freeline/ 55 | freeline_project_description.json 56 | test.php 57 | composer.phar 58 | /vendor/ 59 | -------------------------------------------------------------------------------- /src/AliPay/AliPayComm.php: -------------------------------------------------------------------------------- 1 | share = $raw; 18 | $this->pub_key = $key; 19 | } 20 | 21 | public function isSuccessful() 22 | { 23 | $status = [ 24 | "TRADE_SUCCESS", //商户支持退款 支付成功返回 25 | "TRADE_FINISHED" //商户不支持退款 或者 已经过期 26 | ]; 27 | 28 | if (in_array($this->share["trade_status"], $status)) { 29 | if ($this->checkAliPayNotifyMessage($this->share, $this->pub_key)) { 30 | return true; 31 | } 32 | } 33 | 34 | return false; 35 | } 36 | 37 | /** 38 | * 支付宝支付處理成功後輸出 39 | * @return bool|string 40 | */ 41 | public function sayOK() 42 | { 43 | return "success"; 44 | } 45 | 46 | public function getRequestData() 47 | { 48 | return $this->share; 49 | } 50 | 51 | } -------------------------------------------------------------------------------- /src/WeChat/WeChatComm.php: -------------------------------------------------------------------------------- 1 | 10 | */ 11 | interface WeChatComm 12 | { 13 | /** 14 | * 设置微信公众账号ID 15 | * @param string $app_id 微信公众号ID 16 | * @return mixed 17 | */ 18 | public function setAppId($app_id); 19 | 20 | /** 21 | * 设置微信商户号 22 | * @param string $mch_id 商户ID 23 | * @return mixed 24 | */ 25 | public function setMchId($mch_id); 26 | 27 | /** 28 | * 设置微信支付密钥 29 | * @param string $key 微信支付密钥 30 | * @return mixed 31 | */ 32 | public function setApiKey($key); 33 | 34 | /** 35 | * 退款 36 | * @param string $ca_path; 37 | * @param array $order; 38 | * @return mixed 39 | */ 40 | public function refundOrder($order, $ca_path); 41 | /** 42 | * 撤销订单 43 | * @param string $ca_path; 44 | * @param array $order; 45 | * @return mixed 46 | */ 47 | public function reverseOrder($order, $ca_path); 48 | 49 | /** 50 | * 查询退款状态 51 | * @param $order 52 | * @return mixed 53 | */ 54 | public function queryRefundState($order); 55 | } -------------------------------------------------------------------------------- /src/WeChat/WeChatRequest.php: -------------------------------------------------------------------------------- 1 | share = $data; 20 | $this->api_key = $key; 21 | } 22 | 23 | public function isSuccessful() 24 | { 25 | if ($this->share["result_code"] == "SUCCESS" and $this->share["return_code"] == "SUCCESS") { 26 | if ($this->checkSignature($this->share, $this->api_key)) { 27 | return true; 28 | } 29 | } 30 | 31 | return false; 32 | } 33 | 34 | /** 35 | * 微信支付處理成功後輸出 36 | * @return bool|string 37 | */ 38 | public function sayOK() 39 | { 40 | $result = []; 41 | $result["return_code"] = "SUCCESS"; 42 | $result["return_msg"] = "OK"; 43 | 44 | return $this->toXML($result); 45 | } 46 | 47 | public function getRequestData() 48 | { 49 | return $this->share; 50 | } 51 | 52 | } -------------------------------------------------------------------------------- /src/WeChat/WeChatResponse.php: -------------------------------------------------------------------------------- 1 | getBody(); 19 | $parse = simplexml_load_string($body, "SimpleXMLElement", LIBXML_NOCDATA); 20 | $json = json_encode($parse); 21 | $response_data = json_decode($json, TRUE); 22 | 23 | $this->response_data = $response_data; 24 | $this->request_data = $request_data; 25 | $this->key = $key; 26 | 27 | if (json_last_error() !== JSON_ERROR_NONE) { 28 | throw new \RuntimeException("Got an runtime error, can't decoded response data," 29 | . "json_last_error is" . json_last_error() 30 | . ", please see http://php.net/manual/en/function.json-last-error.php"); 31 | } 32 | 33 | } 34 | 35 | public function getResponseData() 36 | { 37 | return $this->response_data; 38 | } 39 | 40 | public function getRequestData() 41 | { 42 | return $this->request_data; 43 | } 44 | 45 | public function isSuccessful() 46 | { 47 | if ($this->response_data["return_code"] == "SUCCESS" and $this->response_data["result_code"] == "SUCCESS") { 48 | if ($this->checkSignature($this->response_data, $this->key)) { 49 | return true; 50 | } 51 | 52 | return false; 53 | } 54 | 55 | return false; 56 | } 57 | } -------------------------------------------------------------------------------- /src/AliPay/AliPayResponse.php: -------------------------------------------------------------------------------- 1 | getBody(); 20 | $this->request_data = $request_data; 21 | $response_data = json_decode($body, true); 22 | if (json_last_error() !== JSON_ERROR_NONE) { 23 | throw new \RuntimeException("Got an runtime error, can't decoded response data," 24 | . "json_last_error is " . json_last_error() 25 | . ", please see http://php.net/manual/en/function.json-last-error.php"); 26 | } 27 | 28 | $this->response_data = $response_data; 29 | $this->key = $key; 30 | 31 | } 32 | 33 | public function getResponseData() 34 | { 35 | return $this->response_data; 36 | } 37 | 38 | public function getRequestData() 39 | { 40 | return $this->request_data; 41 | } 42 | 43 | public function isSuccessful() 44 | { 45 | $keys = [ 46 | "alipay.trade.pay" => "alipay_trade_pay_response", 47 | "alipay.trade.query" => "alipay_trade_query_response", 48 | "alipay.trade.refund" => "alipay_trade_refund_response", 49 | "alipay.trade.cancel" => "alipay_trade_cancel_response", 50 | "alipay.trade.fastpay.refund.query" => "alipay_trade_fastpay_refund_query_response", 51 | "alipay.trade.precreate" => "alipay_trade_precreate_response", 52 | "alipay.trade.create" => "alipay_trade_create_response" 53 | ]; 54 | 55 | $method = $this->request_data["method"]; 56 | if (array_key_exists($keys[$method], $this->response_data)) { 57 | if (array_key_exists("code", $this->response_data[$keys[$method]])) { 58 | if ($this->response_data[$keys[$method]]["code"] == "10000" 59 | and $this->response_data[$keys[$method]]["msg"] == "Success" 60 | ) { 61 | return true; 62 | } 63 | } 64 | } 65 | return false; 66 | } 67 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # EasyPay 2 | 3 | 轻松集成支付宝,微信支付 到您的业务逻辑中。 4 | 5 | 6 | #### 我该怎么下载安装 7 | 8 | ```php 9 | composer require fantasystudio/easypay 10 | ``` 11 | 12 | #### 我想看看一些代码 13 | 14 | ```php 15 | use \FantasyStudio\EasyPay\AliPay\Qr\Qr; 16 | 17 | $qr = new Qr(); 18 | $qr->setAppId("201703300571632"); 19 | $qr->setSignType("RSA"); 20 | $qr->setPrivateKey("私钥内容,不要携带-----BEGIN RSA PRIVATE KEY-----"); 21 | $qr->purchase([ 22 | "total_amount" => 0.01, "out_trade_no" => "2120960179264092", "subject" => "subjectaa" 23 | ]); 24 | 25 | $result = $qr->sendPaymentRequest(); //发起扫码支付 26 | 27 | var_dump($result->getRequestData()); //获取请求数据 28 | var_dump($result->getResponseData()); //获取网关响应数据 29 | var_dump($result->isSuccessful()); // 请求是否成功 30 | 31 | 32 | ``` 33 | 34 | 35 | 36 | #### 开始集成 37 | 38 | | 分类 | 网关 | 描述 | 相关链接 | 39 | | ---- | ------ | ------------ | ---------------------------------------- | 40 | | 支付宝 | Qr | 扫码支付 | [官方文档](https://docs.open.alipay.com/194/106078/) \| [使用文档](https://github.com/thefantasystudio/easypay/wiki/%E6%94%AF%E4%BB%98%E5%AE%9D-%E6%89%AB%E7%A0%81%E6%94%AF%E4%BB%98) | 41 | | 支付宝 | Pos | 条码支付 | [官方文档](https://docs.open.alipay.com/194/106039/) \| [使用文档](https://github.com/thefantasystudio/easypay/wiki/%E6%94%AF%E4%BB%98%E5%AE%9D-%E6%9D%A1%E7%A0%81%E6%94%AF%E4%BB%98) | 42 | | 支付宝 | JSApi | 支付宝容器内支付(类似微信JSSDK支付) | [官方文档](https://docs.open.alipay.com/api_1/alipay.trade.create) \| [使用文档](https://github.com/thefantasystudio/easypay/wiki/%E6%94%AF%E4%BB%98%E5%AE%9D-%E5%AE%B9%E5%99%A8%E5%86%85%E6%94%AF%E4%BB%98) | 43 | | 支付宝 | Web | 电脑网站支付 | [官方文档](https://docs.open.alipay.com/270) \| [未完成]() | 44 | | 支付宝 | Wap | 手机网站支付 | [官方文档](https://docs.open.alipay.com/203) \| [未完成]() | 45 | | 支付宝 | App | APP支付 | [官方文档](https://docs.open.alipay.com/204/105465/) \| [使用文档](https://github.com/thefantasystudio/easypay/wiki/%E6%94%AF%E4%BB%98%E5%AE%9DApp%E6%94%AF%E4%BB%98) | 46 | | 微信支付 | Pos | 刷卡支付 | [官方文档](https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=5_1) \| [使用文档](https://github.com/thefantasystudio/easypay/wiki/%E5%BE%AE%E4%BF%A1-%E5%88%B7%E5%8D%A1%E6%94%AF%E4%BB%98) | 47 | | 微信支付 | JSApi | 公众号支付(JSSDK) | [官方文档](https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=7_1) \| [使用文档](https://github.com/thefantasystudio/easypay/wiki/%E5%BE%AE%E4%BF%A1-%E5%85%AC%E4%BC%97%E5%8F%B7%E6%94%AF%E4%BB%98) | 48 | | 微信支付 | Native | 扫码支付 | [官方文档](https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=6_1) \| [使用文档](https://github.com/thefantasystudio/easypay/wiki/%E5%BE%AE%E4%BF%A1-%E6%89%AB%E7%A0%81%E6%94%AF%E4%BB%98) | 49 | | 微信支付 | App | APP支付 | [官方文档](https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=8_1) \| [使用文档](https://github.com/thefantasystudio/easypay/wiki/%E5%BE%AE%E4%BF%A1-APP%E6%94%AF%E4%BB%98) | 50 | | 微信支付 | H5 | H5支付 | [官方文档](https://pay.weixin.qq.com/wiki/doc/api/H5.php?chapter=15_1) \| [使用文档](https://github.com/thefantasystudio/easypay/wiki/%E5%BE%AE%E4%BF%A1-H5%E6%94%AF%E4%BB%98) | 51 | -------------------------------------------------------------------------------- /src/AliPay/Pos/Pos.php: -------------------------------------------------------------------------------- 1 | sign_type = $type; 28 | } 29 | 30 | public function setBaseData($data) 31 | { 32 | $this->base = $data; 33 | } 34 | 35 | public function preProcess() 36 | { 37 | return array_merge([ 38 | "app_id" => $this->app_id, 39 | "format" => "JSON", 40 | "charset" => "utf-8", 41 | "sign_type" => $this->sign_type, 42 | "timestamp" => date("Y-m-d H:i:s"), 43 | "version" => "1.0" 44 | ], $this->base); 45 | } 46 | 47 | public function queryRefundState($order) 48 | { 49 | $this->method = "alipay.trade.fastpay.refund.query"; 50 | return $this->sendRequest($this->gateway_url, "POST", $order, "", $this->private_key); 51 | } 52 | 53 | public function purchase($order) 54 | { 55 | $require_field = [ 56 | "out_trade_no", "scene", "auth_code", "subject" 57 | ]; 58 | 59 | foreach ($require_field as $key => $field) { 60 | if (!array_key_exists($field, $order)) { 61 | throw new \InvalidArgumentException("The {$field} field is required, see detail https://docs.open.alipay.com/api_1/alipay.trade.pay"); 62 | } 63 | } 64 | 65 | $this->order = $order; 66 | } 67 | 68 | public function reverseOrder($order) 69 | { 70 | $this->method = "alipay.trade.cancel"; 71 | return $this->sendRequest($this->gateway_url, "POST", $order, "", $this->private_key); 72 | } 73 | 74 | public function refundOrder($order) 75 | { 76 | $this->method = "alipay.trade.refund"; 77 | return $this->sendRequest($this->gateway_url, "POST", $order, "", $this->private_key); 78 | } 79 | 80 | public function setAppId($app_id) 81 | { 82 | $this->app_id = $app_id; 83 | } 84 | 85 | public function setNotifyUrl($url) 86 | { 87 | $this->notify_url; 88 | } 89 | 90 | public function setPrivateKey($content) 91 | { 92 | $this->private_key = $content; 93 | } 94 | 95 | public function sendPaymentRequest() 96 | { 97 | $this->method = "alipay.trade.pay"; 98 | return $this->sendRequest($this->gateway_url, "POST", $this->order, "", $this->private_key); 99 | } 100 | 101 | public function queryOrderState($data) 102 | { 103 | $this->method = "alipay.trade.query"; 104 | return $this->sendRequest($this->gateway_url, "POST", $data, "", $this->private_key); 105 | } 106 | } -------------------------------------------------------------------------------- /src/AliPay/Web/Web.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | class Web implements AliPayComm, PaymentComm 17 | { 18 | use Foundation; 19 | 20 | public $app_id; 21 | public $public_key; 22 | private $private_key; 23 | public $notify_url; 24 | public $order; 25 | public $sign_type; 26 | public $base = []; 27 | public $gateway = "alipay"; 28 | public $postCharset = "UTF-8"; 29 | 30 | 31 | public $gateway_url = "https://openapi.alipay.com/gateway.do"; 32 | 33 | 34 | public function setBaseData($data) 35 | { 36 | $this->base = $data; 37 | } 38 | 39 | public function setSignType($type) 40 | { 41 | $this->sign_type = $type; 42 | } 43 | 44 | public function preProcess() 45 | { 46 | $pre_order = []; 47 | $pre_order["app_id"] = $this->app_id; 48 | $pre_order["method"] = "alipay.trade.page.pay"; 49 | $pre_order["charset"] = "utf-8"; //TODO 仅支持utf8 50 | $pre_order["timestamp"] = date("Y-m-d H:i:s"); 51 | $pre_order["version"] = "1.0"; 52 | $pre_order["sign_type"] = $this->sign_type; 53 | 54 | $base = $this->base; 55 | 56 | return array_merge($pre_order, $base); 57 | } 58 | 59 | 60 | /** 61 | * 建立请求,以表单HTML形式构造(默认) 62 | * @param $form_params 请求参数数组 63 | * @return 提交表单HTML文本 64 | */ 65 | protected function buildRequestForm($form_params) 66 | { 67 | 68 | $form_params["sign"] = $this->makeSignature($form_params, $this->private_key); 69 | $sHtml = "
"; 74 | $sHtml = $sHtml . ""; 75 | 76 | return $sHtml; 77 | } 78 | 79 | 80 | public function sendPaymentRequest() 81 | { 82 | return $this->buildRequestForm($this->order); 83 | } 84 | 85 | public function purchase($order) 86 | { 87 | $data = []; 88 | $order["product_code"] = "FAST_INSTANT_TRADE_PAY"; 89 | 90 | $required = [ 91 | "out_trade_no", "total_amount", "subject" 92 | ]; 93 | 94 | foreach ($required as $k => $field) { 95 | if (!array_key_exists($field, $order)) { 96 | throw new \InvalidArgumentException("The {$field} field is required"); 97 | } 98 | } 99 | 100 | $data["biz_content"] = json_encode($order); 101 | $this->order = array_merge($this->preProcess(), $data); 102 | 103 | } 104 | 105 | public function queryOrderState($data) 106 | { 107 | 108 | } 109 | 110 | public function reverseOrder($order) 111 | { 112 | 113 | } 114 | 115 | 116 | public function setPrivateKey($content) 117 | { 118 | $this->private_key = $content; 119 | } 120 | 121 | public function setNotifyUrl($url) 122 | { 123 | 124 | } 125 | 126 | public function setAppId($app_id) 127 | { 128 | $this->app_id = $app_id; 129 | } 130 | 131 | public function refundOrder($order) 132 | { 133 | 134 | } 135 | 136 | } -------------------------------------------------------------------------------- /src/WeChat/JSApi/JSApi.php: -------------------------------------------------------------------------------- 1 | app_id; 48 | $pre_data["mch_id"] = $this->mch_id; 49 | $pre_data["nonce_str"] = $this->random(); 50 | return $pre_data; 51 | } 52 | 53 | public function purchase($data) 54 | { 55 | $pre_data = $this->preProcess(); 56 | 57 | $pre_data["sign_type"] = "MD5"; 58 | $pre_data["spbill_create_ip"] = $this->get_client_ip() == "::1" ? "127.0.0.1" : $this->get_client_ip(); 59 | $order = array_merge($pre_data, $data); 60 | 61 | $require_field = [ 62 | "appid", "mch_id", "nonce_str", "body", "out_trade_no", "total_fee", "spbill_create_ip", "notify_url", 63 | "trade_type" 64 | ]; 65 | 66 | foreach ($require_field as $key => $field) { 67 | if (!array_key_exists($field, $order)) { 68 | throw new \InvalidArgumentException("The {$field} field is required"); 69 | } 70 | } 71 | 72 | $this->order = $order; 73 | } 74 | 75 | public function sendPaymentRequest() 76 | { 77 | return $this->sendRequest($this->unifiedorder_url, "POST", $this->order, ""); 78 | } 79 | 80 | public function queryOrderState($order) 81 | { 82 | return $this->sendRequest($this->orderquery_url, "POST", $order, ""); 83 | } 84 | 85 | public function refundOrder($order, $ca_path) 86 | { 87 | return $this->sendRequest($this->refund_url, "POST", $order, $ca_path); 88 | 89 | } 90 | 91 | 92 | public function reverseOrder($order, $ca_path) 93 | { 94 | return $this->sendRequest($this->closeorder_url, "POST", $order, $ca_path); 95 | } 96 | 97 | public function closeOrder($order, $ca_path) 98 | { 99 | return $this->sendRequest($this->closeorder_url, "POST", $order, $ca_path); 100 | } 101 | 102 | public function refundQuery($order) 103 | { 104 | return $this->sendRequest($this->refund_query_url, "POST", $order, ""); 105 | } 106 | 107 | public function queryRefundState($order) 108 | { 109 | return $this->sendRequest($this->refund_query_url, "POST", $order, ""); 110 | } 111 | 112 | public function processNotifyMessage($raw_data) 113 | { 114 | return new WeChatRequest($raw_data, $this->api_key); 115 | } 116 | 117 | 118 | public function setApiKey($id) 119 | { 120 | $this->api_key = $id; 121 | } 122 | 123 | public function setMchId($mch_id) 124 | { 125 | $this->mch_id = $mch_id; 126 | } 127 | 128 | public function setAppId($app_id) 129 | { 130 | $this->app_id = $app_id; 131 | } 132 | } -------------------------------------------------------------------------------- /src/WeChat/Pos/Pos.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | class Pos implements WeChatComm, PaymentComm 17 | { 18 | use Foundation; 19 | 20 | private $app_id; 21 | private $api_key; 22 | private $mch_id; 23 | public $order = []; 24 | public $gateway = "wechat"; 25 | 26 | /** 27 | * 提交刷卡支付URL 28 | * @var string 29 | */ 30 | public $micropay_url = "https://api.mch.weixin.qq.com/pay/micropay"; 31 | 32 | /** 33 | * 查询订单URL 34 | * @var string 35 | */ 36 | public $orderquery_url = "https://api.mch.weixin.qq.com/pay/orderquery"; 37 | /** 38 | * 申请退款URL 39 | * @var string 40 | */ 41 | public $refund_url = "https://api.mch.weixin.qq.com/secapi/pay/refund"; 42 | 43 | /** 44 | * 撤销订单URL 45 | * @var string 46 | */ 47 | public $reverse_url = "https://api.mch.weixin.qq.com/secapi/pay/reverse"; 48 | 49 | /** 50 | * 查询退款 51 | * @var string 52 | */ 53 | public $refund_query_url = "https://api.mch.weixin.qq.com/pay/refundquery"; 54 | 55 | public function preProcess() 56 | { 57 | $pre_data["appid"] = $this->app_id; 58 | $pre_data["mch_id"] = $this->mch_id; 59 | $pre_data["nonce_str"] = $this->random(); 60 | return $pre_data; 61 | } 62 | 63 | public function purchase($data) 64 | { 65 | $pre_data = $this->preProcess(); 66 | 67 | $pre_data["sign_type"] = "MD5"; 68 | $pre_data["spbill_create_ip"] = $this->get_client_ip() == "::1" ? "127.0.0.1" : $this->get_client_ip(); 69 | $order = array_merge($pre_data, $data); 70 | 71 | if (empty($order["appid"])) { 72 | throw new \InvalidArgumentException("The appid field is required"); 73 | } 74 | if (empty($order["mch_id"])) { 75 | throw new \InvalidArgumentException("The mch_id field is required"); 76 | } 77 | 78 | if (empty($order["total_fee"])) { 79 | throw new \InvalidArgumentException("The total_fee field is required"); 80 | } 81 | if (!array_key_exists("auth_code", $order) or empty($order["auth_code"])) { 82 | throw new \InvalidArgumentException("The auth_code field is required"); 83 | } 84 | 85 | if (!array_key_exists("out_trade_no", $order) or empty($order["out_trade_no"])) { 86 | throw new \InvalidArgumentException("The out_trade_no field is required"); 87 | } 88 | 89 | $this->order = $order; 90 | } 91 | 92 | public function sendPaymentRequest() 93 | { 94 | return $this->sendRequest($this->micropay_url, "POST", $this->order, ""); 95 | } 96 | 97 | public function queryOrderState($data) 98 | { 99 | return $this->sendRequest($this->orderquery_url, "POST", $data, ""); 100 | } 101 | 102 | public function queryRefundState($data) 103 | { 104 | return $this->sendPaymentRequest($this->refund_query_url, "POST", $data, ""); 105 | } 106 | 107 | public function refundOrder($order, $ca_path) 108 | { 109 | return $this->sendRequest($this->refund_url, "POST", $order, $ca_path); 110 | } 111 | 112 | 113 | public function reverseOrder($order, $ca_path) 114 | { 115 | return $this->sendRequest($this->reverse_url, "POST", $order, $ca_path); 116 | } 117 | 118 | 119 | public function setApiKey($id) 120 | { 121 | $this->api_key = $id; 122 | } 123 | 124 | public function setMchId($mch_id) 125 | { 126 | $this->mch_id = $mch_id; 127 | } 128 | 129 | public function setAppId($app_id) 130 | { 131 | $this->app_id = $app_id; 132 | } 133 | } -------------------------------------------------------------------------------- /src/WeChat/App/App.php: -------------------------------------------------------------------------------- 1 | sendRequest($this->refund_query_url, "POST", $order, "", $this->api_key); 48 | } 49 | 50 | public function preProcess() 51 | { 52 | $pre_data["appid"] = $this->app_id; 53 | $pre_data["mch_id"] = $this->mch_id; 54 | $pre_data["nonce_str"] = $this->random(); 55 | return $pre_data; 56 | } 57 | 58 | public function purchase($data) 59 | { 60 | $pre_data = $this->preProcess(); 61 | 62 | $pre_data["sign_type"] = "MD5"; 63 | $pre_data["spbill_create_ip"] = $this->get_client_ip() == "::1" ? "127.0.0.1" : $this->get_client_ip(); 64 | $order = array_merge($pre_data, $data); 65 | 66 | $require_field = [ 67 | "appid", "mch_id", "nonce_str", "body", "out_trade_no", "total_fee", "spbill_create_ip", "notify_url", 68 | "trade_type" 69 | ]; 70 | 71 | foreach ($require_field as $key => $field) { 72 | if (!array_key_exists($field, $order)) { 73 | throw new \InvalidArgumentException("The {$field} field is required"); 74 | } 75 | } 76 | $this->order = $order; 77 | } 78 | 79 | public function sendPaymentRequest() 80 | { 81 | return $this->sendRequest($this->unifiedorder_url, "POST", $this->order, "", $this->api_key); 82 | } 83 | 84 | public function queryOrderState($order) 85 | { 86 | return $this->sendRequest($this->orderquery_url, "POST", $order, "", $this->api_key); 87 | } 88 | 89 | public function refundOrder($order, $ca_path) 90 | { 91 | return $this->sendRequest($this->refund_url, "POST", $order, $ca_path, $this->api_key); 92 | 93 | } 94 | 95 | 96 | public function reverseOrder($order, $ca_path) 97 | { 98 | return $this->sendRequest($this->closeorder_url, "POST", $order, $ca_path, $this->api_key); 99 | } 100 | 101 | public function closeOrder($order, $ca_path) 102 | { 103 | return $this->sendRequest($this->closeorder_url, "POST", $order, $ca_path, $this->api_key); 104 | } 105 | 106 | public function refundQuery($order) 107 | { 108 | return $this->sendRequest($this->refund_query_url, "POST", $order, "", $this->api_key); 109 | } 110 | 111 | public function processNotifyMessage($raw_data) 112 | { 113 | return new WeChatRequest($raw_data, $this->api_key); 114 | } 115 | 116 | 117 | public function setApiKey($id) 118 | { 119 | $this->api_key = $id; 120 | } 121 | 122 | public function setMchId($mch_id) 123 | { 124 | $this->mch_id = $mch_id; 125 | } 126 | 127 | public function setAppId($app_id) 128 | { 129 | $this->app_id = $app_id; 130 | } 131 | } -------------------------------------------------------------------------------- /src/WeChat/H5/H5.php: -------------------------------------------------------------------------------- 1 | sendRequest($this->refund_query_url, "POST", $order, "", $this->api_key); 48 | } 49 | 50 | public function preProcess() 51 | { 52 | $pre_data["appid"] = $this->app_id; 53 | $pre_data["mch_id"] = $this->mch_id; 54 | $pre_data["nonce_str"] = $this->random(); 55 | return $pre_data; 56 | } 57 | 58 | public function purchase($data) 59 | { 60 | $pre_data = $this->preProcess(); 61 | 62 | $pre_data["sign_type"] = "MD5"; 63 | $pre_data["spbill_create_ip"] = $this->get_client_ip() == "::1" ? "127.0.0.1" : $this->get_client_ip(); 64 | $order = array_merge($pre_data, $data); 65 | 66 | $require_field = [ 67 | "appid", "mch_id", "nonce_str", "body", "out_trade_no", "total_fee", "spbill_create_ip", "notify_url", 68 | "trade_type","scene_info" 69 | ]; 70 | 71 | foreach ($require_field as $key => $field) { 72 | if (!array_key_exists($field, $order)) { 73 | throw new \InvalidArgumentException("The {$field} field is required"); 74 | } 75 | } 76 | $this->order = $order; 77 | } 78 | 79 | public function sendPaymentRequest() 80 | { 81 | return $this->sendRequest($this->unifiedorder_url, "POST", $this->order, "", $this->api_key); 82 | } 83 | 84 | public function queryOrderState($order) 85 | { 86 | return $this->sendRequest($this->orderquery_url, "POST", $order, "", $this->api_key); 87 | } 88 | 89 | public function refundOrder($order, $ca_path) 90 | { 91 | return $this->sendRequest($this->refund_url, "POST", $order, $ca_path, $this->api_key); 92 | 93 | } 94 | 95 | 96 | public function reverseOrder($order, $ca_path) 97 | { 98 | return $this->sendRequest($this->closeorder_url, "POST", $order, $ca_path, $this->api_key); 99 | } 100 | 101 | public function closeOrder($order, $ca_path) 102 | { 103 | return $this->sendRequest($this->closeorder_url, "POST", $order, $ca_path, $this->api_key); 104 | } 105 | 106 | public function refundQuery($order) 107 | { 108 | return $this->sendRequest($this->refund_query_url, "POST", $order, "", $this->api_key); 109 | } 110 | 111 | public function processNotifyMessage($raw_data) 112 | { 113 | return new WeChatRequest($raw_data, $this->api_key); 114 | } 115 | 116 | 117 | public function setApiKey($id) 118 | { 119 | $this->api_key = $id; 120 | } 121 | 122 | public function setMchId($mch_id) 123 | { 124 | $this->mch_id = $mch_id; 125 | } 126 | 127 | public function setAppId($app_id) 128 | { 129 | $this->app_id = $app_id; 130 | } 131 | } -------------------------------------------------------------------------------- /src/AliPay/JSApi/JSApi.php: -------------------------------------------------------------------------------- 1 | sign_type = $type; 31 | } 32 | 33 | public function setBaseData($data) 34 | { 35 | $this->base = $data; 36 | } 37 | 38 | public function preProcess() 39 | { 40 | $arr = array_merge([ 41 | "app_id" => $this->app_id, 42 | "format" => "JSON", 43 | "charset" => "utf-8", 44 | "sign_type" => $this->sign_type, 45 | "timestamp" => date("Y-m-d H:i:s"), 46 | "version" => "1.0", 47 | "notify_url" => $this->notify_url, 48 | ], $this->base); 49 | 50 | if ($this->enable_koubei_promo == true) { 51 | $arr["promo_params"] = "{\"kborder_flag\":\"order\"}"; 52 | } 53 | return $arr; 54 | } 55 | 56 | public function setPublicKey($key) 57 | { 58 | $this->public_key = $key; 59 | } 60 | 61 | public function queryRefundState($order) 62 | { 63 | $this->method = "alipay.trade.fastpay.refund.query"; 64 | return $this->sendRequest($this->gateway_url, "POST", $order, "", $this->private_key); 65 | } 66 | 67 | public function purchase($order) 68 | { 69 | $require_field = [ 70 | "out_trade_no", "total_amount", "subject", "buyer_id" 71 | ]; 72 | 73 | foreach ($require_field as $key => $field) { 74 | if (!array_key_exists($field, $order)) { 75 | throw new \InvalidArgumentException("The {$field} field is required, see detail https://docs.open.alipay.com/api_1/alipay.trade.pay"); 76 | } 77 | } 78 | 79 | $this->order = $order; 80 | } 81 | 82 | public function reverseOrder($order) 83 | { 84 | $this->method = "alipay.trade.cancel"; 85 | return $this->sendRequest($this->gateway_url, "POST", $order, "", $this->private_key); 86 | } 87 | 88 | public function refundOrder($order) 89 | { 90 | $this->method = "alipay.trade.refund"; 91 | return $this->sendRequest($this->gateway_url, "POST", $order, "", $this->private_key); 92 | } 93 | 94 | public function setAppId($app_id) 95 | { 96 | $this->app_id = $app_id; 97 | } 98 | 99 | public function setNotifyUrl($url) 100 | { 101 | $this->notify_url = $url; 102 | } 103 | 104 | public function setPrivateKey($content) 105 | { 106 | $this->private_key = $content; 107 | } 108 | 109 | public function sendPaymentRequest() 110 | { 111 | $this->method = "alipay.trade.create"; 112 | return $this->sendRequest($this->gateway_url, "POST", $this->order, "", $this->private_key); 113 | } 114 | 115 | public function queryOrderState($data) 116 | { 117 | $this->method = "alipay.trade.query"; 118 | return $this->sendRequest($this->gateway_url, "POST", $data, "", $this->private_key); 119 | } 120 | 121 | public function enableKoubeiPromo($bool) 122 | { 123 | $this->enable_koubei_promo = $bool; 124 | } 125 | 126 | public function processNotifyMessage($message) 127 | { 128 | return new AliPayRequest($message, $this->public_key); 129 | } 130 | } -------------------------------------------------------------------------------- /src/WeChat/Native/Native.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | class Native implements WeChatComm, PaymentComm 17 | { 18 | use Foundation; 19 | 20 | private $app_id; 21 | private $api_key; 22 | private $mch_id; 23 | public $order = []; 24 | public $gateway = "wechat"; 25 | 26 | /** 27 | * 统一下单URL 28 | * @var string 29 | */ 30 | public $unifiedorder_url = "https://api.mch.weixin.qq.com/pay/unifiedorder"; 31 | /** 32 | * 订单查询URL 33 | * @var string 34 | */ 35 | public $orderquery_url = "https://api.mch.weixin.qq.com/pay/orderquery"; 36 | /** 37 | * 关闭订单URL 38 | * @var string 39 | */ 40 | public $closeorder_url = "https://api.mch.weixin.qq.com/pay/closeorder"; 41 | /** 42 | * 申请退款URL 43 | * @var string 44 | */ 45 | public $refund_url = "https://api.mch.weixin.qq.com/secapi/pay/refund"; 46 | /** 47 | * 查询退款URL 48 | * @var string 49 | */ 50 | public $refund_query_url = "https://api.mch.weixin.qq.com/pay/refundquery"; 51 | 52 | public function preProcess() 53 | { 54 | $pre_data["appid"] = $this->app_id; 55 | $pre_data["mch_id"] = $this->mch_id; 56 | $pre_data["nonce_str"] = "uBFpfrllIoFxWQnz";//$this->random(); 57 | return $pre_data; 58 | } 59 | 60 | public function purchase($data) 61 | { 62 | $pre_data = $this->preProcess(); 63 | 64 | $pre_data["sign_type"] = "MD5"; 65 | $pre_data["spbill_create_ip"] = $this->get_client_ip() == "::1" ? "127.0.0.1" : $this->get_client_ip(); 66 | $order = array_merge($pre_data, $data); 67 | 68 | $require_field = [ 69 | "appid", "mch_id", "nonce_str", "body","product_id", "out_trade_no", "total_fee", "spbill_create_ip", "notify_url", 70 | "trade_type" 71 | ]; 72 | 73 | foreach ($require_field as $key => $field) { 74 | if (!array_key_exists($field, $order)) { 75 | throw new \InvalidArgumentException("The {$field} field is required"); 76 | } 77 | } 78 | 79 | $this->order = $order; 80 | } 81 | 82 | public function sendPaymentRequest() 83 | { 84 | return $this->sendRequest($this->unifiedorder_url, "POST", $this->order, ""); 85 | } 86 | 87 | public function queryOrderState($order) 88 | { 89 | return $this->sendRequest($this->orderquery_url, "POST", $order, ""); 90 | } 91 | 92 | public function refundOrder($order, $ca_path) 93 | { 94 | return $this->sendRequest($this->refund_url, "POST", $order, $ca_path); 95 | 96 | } 97 | 98 | public function queryRefundState($order) 99 | { 100 | return $this->sendRequest($this->refund_query_url, "POST", $order); 101 | } 102 | 103 | public function reverseOrder($order, $ca_path) 104 | { 105 | return $this->sendRequest($this->closeorder_url, "POST", $order, $ca_path); 106 | } 107 | 108 | public function closeOrder($order) 109 | { 110 | return $this->sendRequest($this->closeorder_url, "POST", $order); 111 | } 112 | 113 | public function refundQuery($order) 114 | { 115 | return $this->sendRequest($this->refundquery_url, "POST", $order, ""); 116 | } 117 | 118 | public function processNotifyMessage($raw_data) 119 | { 120 | return new WeChatRequest($raw_data, $this->api_key); 121 | } 122 | 123 | 124 | public function setApiKey($id) 125 | { 126 | $this->api_key = $id; 127 | } 128 | 129 | public function setMchId($mch_id) 130 | { 131 | $this->mch_id = $mch_id; 132 | } 133 | 134 | public function setAppId($app_id) 135 | { 136 | $this->app_id = $app_id; 137 | } 138 | } -------------------------------------------------------------------------------- /src/AliPay/Qr/Qr.php: -------------------------------------------------------------------------------- 1 | sign_type = $type; 30 | } 31 | 32 | public function setBaseData($data) 33 | { 34 | $this->base = $data; 35 | } 36 | 37 | 38 | public function preProcess() 39 | { 40 | $query_params = array_merge([ 41 | "app_id" => $this->app_id, 42 | "format" => "JSON", 43 | "charset" => "utf-8", 44 | "sign_type" => $this->sign_type, 45 | "timestamp" => date("Y-m-d H:i:s"), 46 | "version" => "1.0" 47 | ], $this->base); 48 | 49 | if (!empty($this->notify_url)) { 50 | $query_params["notify_url"] = $this->notify_url; 51 | } 52 | 53 | return $query_params; 54 | } 55 | 56 | public function setNotifyUrl($url) 57 | { 58 | $this->notify_url = $url; 59 | } 60 | 61 | public function setPrivateKey($key) 62 | { 63 | $this->private_key = $key; 64 | } 65 | 66 | public function setPublicKey($key) 67 | { 68 | $this->public_key = $key; 69 | } 70 | 71 | 72 | public function queryOrderState($order) 73 | { 74 | $this->method = "alipay.trade.query"; 75 | return $this->sendRequest($this->gateway_url, "POST", $order, "", $this->private_key); 76 | } 77 | 78 | public function sendPaymentRequest() 79 | { 80 | $this->method = "alipay.trade.precreate"; 81 | return $this->sendRequest($this->gateway_url, "POST", $this->order, ""); 82 | } 83 | 84 | public function queryRefundState($order) 85 | { 86 | $this->method = "alipay.trade.fastpay.refund.query"; 87 | return $this->sendRequest($this->gateway_url, "POST", $order, ""); 88 | } 89 | 90 | public function purchase($order) 91 | { 92 | $require_field = [ 93 | "out_trade_no", "total_amount", "subject" 94 | ]; 95 | 96 | foreach ($require_field as $key => $field) { 97 | if (!array_key_exists($field, $order)) { 98 | throw new \InvalidArgumentException("The {$field} field is required, see detail https://docs.open.alipay.com/api_1/alipay.trade.precreate"); 99 | } 100 | } 101 | 102 | $this->order = $order; 103 | } 104 | 105 | public function refundOrder($order) 106 | { 107 | $this->method = "alipay.trade.refund"; 108 | return $this->sendRequest($this->gateway_url, "POST", $order, "", $this->private_key); 109 | } 110 | 111 | public function reverseOrder($order) 112 | { 113 | $this->method = "alipay.trade.cancel"; 114 | return $this->sendRequest($this->gateway_url, "POST", $order, "", $this->private_key); 115 | } 116 | 117 | public function setAppId($app_id) 118 | { 119 | $this->app_id = $app_id; 120 | } 121 | 122 | public function processNotifyMessage($message) 123 | { 124 | return new AliPayRequest($message, $this->public_key); 125 | } 126 | 127 | public function checkSign($param, $key) 128 | { 129 | $sign = $param["sign"]; 130 | $param["sign"] = null; 131 | $param["sign_type"] = null; 132 | ksort($param); 133 | $query_string = urldecode(http_build_query($param)); 134 | 135 | $res = "-----BEGIN PUBLIC KEY-----\n" . 136 | wordwrap($key, 64, "\n", true) . 137 | "\n-----END PUBLIC KEY-----"; 138 | 139 | $result = openssl_verify($query_string, base64_decode($sign), $res); 140 | if ($result == 1) { 141 | return true; 142 | } 143 | return false; 144 | 145 | } 146 | } -------------------------------------------------------------------------------- /src/AliPay/App/App.php: -------------------------------------------------------------------------------- 1 | 14 | */ 15 | class App implements AliPayComm, PaymentComm 16 | { 17 | use Foundation; 18 | 19 | public $app_id; 20 | public $public_key; 21 | private $private_key; 22 | public $notify_url; 23 | public $sign_type; 24 | public $order; 25 | public $base = []; 26 | public $method; 27 | public $gateway = "alipay"; 28 | public $postCharset = "UTF-8"; 29 | 30 | public $enable_koubei_promo = false; //是否开启口碑折扣 @see https://open.koubei.com/#/solution?type=codeServer&no=koubei_qrcode_orderdishes 31 | 32 | public $gateway_url = "https://openapi.alipay.com/gateway.do"; 33 | 34 | public function setSignType($type) 35 | { 36 | $this->sign_type = $type; 37 | } 38 | 39 | public function setBaseData($data) 40 | { 41 | $this->base = $data; 42 | } 43 | 44 | public function preProcess() 45 | { 46 | $arr = array_merge([ 47 | "app_id" => $this->app_id, 48 | "format" => "JSON", 49 | "charset" => "utf-8", 50 | "sign_type" => $this->sign_type, 51 | "timestamp" => date("Y-m-d H:i:s"), 52 | "version" => "1.0", 53 | "notify_url" => $this->notify_url, 54 | ], $this->base); 55 | 56 | if ($this->enable_koubei_promo == true) { 57 | $arr["promo_params"] = "{\"kborder_flag\":\"order\"}"; 58 | } 59 | return $arr; 60 | } 61 | 62 | public function setPublicKey($key) 63 | { 64 | $this->public_key = $key; 65 | } 66 | 67 | public function queryRefundState($order) 68 | { 69 | $this->method = "alipay.trade.fastpay.refund.query"; 70 | return $this->sendRequest($this->gateway_url, "POST", $order, "", $this->private_key); 71 | } 72 | 73 | public function purchase($order) 74 | { 75 | $require_field = [ 76 | "out_trade_no", "total_amount", "subject", "product_code" 77 | ]; 78 | 79 | foreach ($require_field as $key => $field) { 80 | if (!array_key_exists($field, $order)) { 81 | throw new \InvalidArgumentException("The {$field} field is required, see detail https://docs.open.alipay.com/api_1/alipay.trade.pay"); 82 | } 83 | } 84 | 85 | $this->order = $order; 86 | } 87 | 88 | public function reverseOrder($order) 89 | { 90 | $this->method = "alipay.trade.cancel"; 91 | return $this->sendRequest($this->gateway_url, "POST", $order, "", $this->private_key); 92 | } 93 | 94 | public function refundOrder($order) 95 | { 96 | $this->method = "alipay.trade.refund"; 97 | return $this->sendRequest($this->gateway_url, "POST", $order, "", $this->private_key); 98 | } 99 | 100 | public function setAppId($app_id) 101 | { 102 | $this->app_id = $app_id; 103 | } 104 | 105 | public function setNotifyUrl($url) 106 | { 107 | $this->notify_url = $url; 108 | } 109 | 110 | public function setPrivateKey($content) 111 | { 112 | $this->private_key = $content; 113 | } 114 | 115 | public function sendPaymentRequest() 116 | { 117 | $this->method = "alipay.trade.app.pay"; 118 | $query = $this->preProcess(); 119 | $query["method"] = $this->method; 120 | $query["biz_content"] = json_encode($this->order,JSON_UNESCAPED_UNICODE); 121 | ksort($query); 122 | $query["sign"] = $this->makeSignature($query, $this->private_key); 123 | 124 | return http_build_query($query); 125 | } 126 | 127 | public function queryOrderState($data) 128 | { 129 | $this->method = "alipay.trade.query"; 130 | return $this->sendRequest($this->gateway_url, "POST", $data, "", $this->private_key); 131 | } 132 | 133 | public function enableKoubeiPromo($bool) 134 | { 135 | $this->enable_koubei_promo = $bool; 136 | } 137 | 138 | public function processNotifyMessage($message) 139 | { 140 | return new AliPayRequest($message, $this->public_key); 141 | } 142 | } -------------------------------------------------------------------------------- /src/Foundation/Foundation.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | trait Foundation 17 | { 18 | /** 19 | * 随机字符串 20 | * @param int $length 21 | * @return string 22 | */ 23 | function random($length = 16) 24 | { 25 | $characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; 26 | $charactersLength = strlen($characters); 27 | $randomString = ''; 28 | for ($i = 0; $i < $length; $i++) { 29 | $randomString .= $characters[rand(0, $charactersLength - 1)]; 30 | } 31 | return $randomString; 32 | } 33 | 34 | /** 35 | * 发送支付网络请求 36 | * @param string $url 请求的URL 37 | * @param string $method 请求的method 38 | * @param array $data 请求数据 39 | * @param string $ca_path 是否使用证书 40 | * @throws 41 | * @return object 42 | */ 43 | public function sendRequest($url, $method = "POST", $data, $ca_path = "") 44 | { 45 | $client = new Client(); 46 | 47 | if ($this->gateway == "wechat") { 48 | 49 | $pre = $this->preProcess(); 50 | $query = array_merge($pre, $data); 51 | $query["sign"] = $this->makeSignature($query, $this->api_key); 52 | $xml = $this->toXML($query); 53 | $headers = ['body' => $xml, 'Content-Type' => 'text/xml; charset=UTF8']; 54 | if (!empty($ca_path)) { 55 | $headers["cert"] = $ca_path; 56 | } 57 | $response = $client->request($method, $url, $headers); 58 | return new WeChatResponse($response, $query, $this->api_key); 59 | 60 | 61 | } elseif ($this->gateway == "alipay") { 62 | 63 | $query = $this->preProcess(); 64 | $query["method"] = $this->method; 65 | $query["biz_content"] = json_encode($data); 66 | $query["sign"] = $this->makeSignature($query, $this->private_key); 67 | $response = $client->request("POST", $url, [ 68 | "query" => $query 69 | ]); 70 | return new AliPayResponse($response, $query, $this->private_key); 71 | } 72 | 73 | } 74 | 75 | /** 76 | * array to xml 77 | * @param array $data 78 | * @return bool|string 79 | */ 80 | public function toXML($data) 81 | { 82 | if (!is_array($data) || count($data) == 0) { 83 | return false; 84 | } 85 | 86 | $xml = "