完成微信支付所有网关及其文档

This commit is contained in:
yansongda 2017-08-18 09:59:48 +08:00
parent 781fce183e
commit 7cefa671dc
7 changed files with 97 additions and 43 deletions

View File

@ -234,17 +234,17 @@ $config_biz = [
```
#### 返回值
- pay()
类型string
说明:该接口返回跳转到支付宝支付的 Html 代码。
- pay()
类型string
说明:该接口返回跳转到支付宝支付的 Html 代码。
- refund()
类型bool
说明:退款成功,返回 true
- refund()
类型bool
说明:退款成功,返回 true
- close()
类型bool
说明:关闭成功,返回 true
- close()
类型bool
说明:关闭成功,返回 true
### 2、支付宝 - 手机网站支付
@ -269,17 +269,17 @@ $config_biz = [
该网关大部分参数和 「电脑支付」 相同,具体请参考 [官方文档](https://docs.open.alipay.com/203/107090/ '支付宝手机网站支付文档')
#### 返回值
- pay()
类型string
说明:该接口返回跳转到支付宝支付的 Html 代码。
- pay()
类型string
说明:该接口返回跳转到支付宝支付的 Html 代码。
- refund()
类型bool
说明:退款成功,返回 true
- refund()
类型bool
说明:退款成功,返回 true
- close()
类型bool
说明:关闭成功,返回 true
- close()
类型bool
说明:关闭成功,返回 true
### 3、支付宝 - APP 支付
@ -394,7 +394,7 @@ $config_biz = [
类型array
说明:返回用于 微信内H5调起支付 的所需参数数组。后续调用不在本文档讨论范围内,具体请 [参考这里](https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=7_7&index=6)。
后续调用举例:
后续调用举例:
```html
<script type="text/javascript">
@ -549,8 +549,42 @@ TODO
### 8、微信 - 刷卡支付
#### 最小配置参数
```php
$config = [
'wechat' => [
'app_id' => '', // 公众号 APPID
'mch_id' => '', // 微信商户号
'notify_url' => '',
'key' => '', // 微信支付签名秘钥
],
];
$config_biz = [
'out_trade_no' => '', // 订单号
'total_fee' => '', // 订单金额,单位:元
'body' => '', // 订单描述
'spbill_create_ip' => '', // 支付人的 IP
'auth_code' => '', // 授权码
];
```
#### 所有配置参数
该网关所有参数和其它支付网关基本相同,具体请 [参考这里](https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=9_10&index=1)。
#### 返回值
- pay()
类型array
说明:返回用于服务器返回的数组。返回参数请 [参考这里](https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=9_10&index=1)。
- refund()
TODO
- close()
TODO
### 9、微信 - APP 支付
#### 最小配置参数
```php
$config = [

View File

@ -3,18 +3,18 @@
namespace Yansongda\Pay\Gateways\Wechat;
/**
* 微信 - 公众号支付
* 微信 - 公众号支付.
*/
class AppGateway extends Wechat
{
/**
* 交易类型
* 交易类型.
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-15
*
* @return [type] [description]
* @return string [description]
*/
protected function getTradeType()
{
@ -22,7 +22,7 @@ class AppGateway extends Wechat
}
/**
* 对外支付
* 对外支付.
*
* @author yansongda <me@yansongda.cn>
*
@ -30,7 +30,7 @@ class AppGateway extends Wechat
*
* @param array $config_biz [description]
*
* @return [type] [description]
* @return array [description]
*/
public function pay(array $config_biz = [])
{

View File

@ -14,9 +14,9 @@ class MiniappGateway extends Wechat
*
* @version 2017-08-15
*
* @return [type] [description]
* @return string [description]
*/
public function getTradeType()
protected function getTradeType()
{
return 'JSAPI';
}
@ -30,7 +30,7 @@ class MiniappGateway extends Wechat
*
* @param array $config_biz [description]
*
* @return [type] [description]
* @return array [description]
*/
public function pay(array $config_biz = [])
{

View File

@ -14,7 +14,7 @@ class MpGateway extends Wechat
*
* @version 2017-08-15
*
* @return [type] [description]
* @return string [description]
*/
protected function getTradeType()
{
@ -30,7 +30,7 @@ class MpGateway extends Wechat
*
* @param array $config_biz [description]
*
* @return [type] [description]
* @return array [description]
*/
public function pay(array $config_biz = [])
{

View File

@ -7,6 +7,13 @@ namespace Yansongda\Pay\Gateways\Wechat;
*/
class PosGateway extends Wechat
{
/**
* 刷卡支付 API.
*
* @var string
*/
protected $gateway = 'https://api.mch.weixin.qq.com/pay/micropay';
/**
* [getTradeType description].
*
@ -16,13 +23,26 @@ class PosGateway extends Wechat
*
* @return [type] [description]
*/
public function getTradeType()
protected function getTradeType()
{
return 'JSAPI';
return 'MICROPAY';
}
/**
* [pay description].
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-18
*
* @param array $config_biz [description]
*
* @return array [description]
*/
public function pay(array $config_biz = [])
{
# code...
unset($this->config['trade_type']);
return $this->preOrder();
}
}

View File

@ -14,9 +14,9 @@ class WapGateway extends Wechat
*
* @version 2017-08-15
*
* @return [type] [description]
* @return string [description]
*/
public function getTradeType()
protected function getTradeType()
{
return 'MWEB';
}
@ -30,7 +30,7 @@ class WapGateway extends Wechat
*
* @param array $config_biz [description]
*
* @return [type] [description]
* @return string 支付中间页 url
*/
public function pay(array $config_biz = [])
{

View File

@ -20,19 +20,19 @@ abstract class Wechat implements GatewayInterface
*
* @var string
*/
protected $preOrder_gateway = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
protected $gateway = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
/**
* [$config description].
*
* @var [type]
* @var array
*/
protected $config;
/**
* [$user_config description].
*
* @var [type]
* @var Yansongda\Pay\Support\Config
*/
protected $user_config;
@ -68,7 +68,7 @@ abstract class Wechat implements GatewayInterface
*
* @param array $config_biz [description]
*
* @return [type] [description]
* @return mixed [description]
*/
abstract public function pay(array $config_biz = []);
@ -128,7 +128,7 @@ abstract class Wechat implements GatewayInterface
*
* @version 2017-08-17
*
* @return [type] [description]
* @return string [description]
*/
abstract protected function getTradeType();
@ -145,8 +145,8 @@ abstract class Wechat implements GatewayInterface
{
$this->config['total_fee'] = intval($this->config['total_fee'] * 100);
$this->config['sign'] = $this->getSign($this->config);
$data = $this->fromXml($this->post($this->preOrder_gateway, [], $this->toXml($this->config)));
$data = $this->fromXml($this->post($this->gateway, [], $this->toXml($this->config)));
if (!isset($data['return_code']) || $data['return_code'] !== 'SUCCESS' || $data['result_code'] !== 'SUCCESS') {
$error = 'preOrder error:' . $data['return_msg'];
@ -226,7 +226,7 @@ abstract class Wechat implements GatewayInterface
*
* @param integer $length [description]
*
* @return [type] [description]
* @return string [description]
*/
protected function createNonceStr($length = 16) {
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";