merge to dev : apply styleCI

This commit is contained in:
yansongda 2017-08-15 22:55:04 +08:00
commit 5cd5d82807
17 changed files with 274 additions and 50 deletions

View File

@ -10,19 +10,19 @@
## 支持的支付网关
### 支付宝
### 1、支付宝
- 电脑支付
- 手机网站支付
SDK 中对应的 driver 和 gateway 如下表所示:
SDK 中对应的 driver 和 gateway 如下表所示:
| driver | gateway | 描述 |
| :----: | :-----: | :-------: |
| alipay | web | 电脑支付 |
| alipay | wap | 手机网站支付 |
### 微信
### 2、微信
- 公众号支付
- 小程序支付
@ -139,6 +139,24 @@ $config_biz = [
### 支付宝 - 手机网站支付
1、最小配置参数
```php
$config = [
'alipay' => [
'app_id' => '', // 支付宝提供的 APP_ID
'ali_public_key' => '', // 支付宝公钥1行填写
'private_key' => '', // 自己的私钥1行填写
],
];
$config_biz = [
'out_trade_no' => '12', // 订单号
'total_amount' => '13', // 订单金额,单位:元
'subject' => 'officeal test subject', // 订单商品标题
];
```
2、所有配置参数
该网关大部分参数和 「电脑支付」 相同,具体请参考 [官方文档](https://docs.open.alipay.com/203/107090/ '支付宝手机网站支付文档')
### 微信 - 公众号支付

View File

@ -1,4 +1,4 @@
<?php
<?php
namespace Yansongda\Pay\Contracts;
/**
@ -8,38 +8,54 @@ interface GatewayInterface
{
/**
* 支付
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-15
*
* @param array $config_biz [description]
*
* @return [type] [description]
*/
public function pay(array $config_biz);
/**
* 退款
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-15
*
* @param array $config_biz [description]
*
* @return [type] [description]
*/
public function refund(array $config_biz);
/**
* 关闭
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-15
*
* @param array $config_biz [description]
*
* @return [type] [description]
*/
public function close(array $config_biz);
/**
* 验证消息是否官方发出
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-15
*
* @param mixed $data 待签名数组
* @param string $sign 签名字符串-支付宝服务器发送过来的原始串
* @param bool $sync 是否同步验证
*
* @return [type] [description]
*/
public function verify($data, $sign = null, $sync = false);

View File

@ -1,11 +1,10 @@
<?php
<?php
namespace Yansongda\Pay\Exceptions;
/**
*
*/
* Exception
*/
class Exception extends \Exception
{
}

View File

@ -1,22 +1,26 @@
<?php
<?php
namespace Yansongda\Pay\Exceptions;
/**
* GatewayException
*/
* GatewayException
*/
class GatewayException extends Exception
{
/**
* error raw data
*
* @var array
*/
public $raw = [];
/**
* [__construct description]
*
* @author JasonYan <me@yansongda.cn>
*
* @version 2017-07-28
*
* @param [type] $message [description]
* @param [type] $code [description]
*/

View File

@ -1,11 +1,10 @@
<?php
<?php
namespace Yansongda\Pay\Exceptions;
/**
* InvalidArgumentException
*/
* InvalidArgumentException
*/
class InvalidArgumentException extends \InvalidArgumentException
{
}

View File

@ -1,4 +1,4 @@
<?php
<?php
namespace Yansongda\Pay\Gateways\Alipay;
@ -9,34 +9,40 @@ use Yansongda\Pay\Exceptions\GatewayException;
use Yansongda\Pay\Exceptions\InvalidArgumentException;
/**
*
*/
* abstract class Alipay
*/
abstract class Alipay implements GatewayInterface
{
use HasHttpRequest;
/**
* 支付宝支付网关
*
* @var string
*/
protected $gateway = 'https://openapi.alipaydev.com/gateway.do';
/**
* 支付宝公共参数
*
* @var [type]
*/
protected $config;
/**
* 用户的传参
*
* @var [type]
*/
protected $user_config;
/**
* [__construct description]
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-14
*
* @param array $config [description]
*/
public function __construct(array $config)
@ -65,9 +71,13 @@ abstract class Alipay implements GatewayInterface
/**
* 对外接口 - 支付
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-15
*
* @param array $config_biz [description]
*
* @return [type] [description]
*/
public function pay(array $config_biz = [])
@ -83,9 +93,13 @@ abstract class Alipay implements GatewayInterface
/**
* 对外接口 - 退款
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-15
*
* @param array $config_biz [description]
*
* @return [type] [description]
*/
public function refund(array $config_biz = [])
@ -99,9 +113,13 @@ abstract class Alipay implements GatewayInterface
/**
* 对外接口 - 关闭
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-15
*
* @param array $config_biz [description]
*
* @return [type] [description]
*/
public function close(array $config_biz = [])
@ -115,11 +133,15 @@ abstract class Alipay implements GatewayInterface
/**
* 对外接口 - 验证
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-11
*
* @param array $data 待签名数组
* @param string $sign 签名字符串-支付宝服务器发送过来的原始串
* @param bool $sync 是否同步验证
*
* @return [type] [description]
*/
public function verify($data, $sign = null, $sync = false)
@ -145,24 +167,33 @@ abstract class Alipay implements GatewayInterface
/**
* [getMethod description]
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-10
*
* @return [type] [description]
*/
abstract protected function getPayMethod();
/**
* [getProductCode description]
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-10
*
* @return [type] [description]
*/
abstract protected function getPayProductCode();
/**
* [buildHtmlPay description]
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-11
*
* @return [type] [description]
*/
protected function buildPayHtml()
@ -180,9 +211,13 @@ abstract class Alipay implements GatewayInterface
/**
* get alipay api result
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-12
*
* @param [type] $method [description]
*
* @return [type] [description]
*/
protected function getResult($method)
@ -201,8 +236,11 @@ abstract class Alipay implements GatewayInterface
/**
* 签名
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-10
*
* @return [type] [description]
*/
protected function getSign()
@ -222,10 +260,14 @@ abstract class Alipay implements GatewayInterface
/**
* 待签名数组
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-11
*
* @param array $toBeSigned [description]
* @param boolean $verify 是否异步同时验证签名
*
* @return [type] [description]
*/
protected function getSignContent(array $toBeSigned, $verify = false)

View File

@ -1,16 +1,19 @@
<?php
<?php
namespace Yansongda\Pay\Gateways\Alipay;
/**
*
*/
* WapGateway
*/
class WapGateway extends Alipay
{
/**
* [getMethod description]
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-10
*
* @return [type] [description]
*/
protected function getPayMethod() {
@ -19,8 +22,11 @@ class WapGateway extends Alipay
/**
* [getProductCode description]
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-10
*
* @return [type] [description]
*/
protected function getPayProductCode() {

View File

@ -1,16 +1,19 @@
<?php
<?php
namespace Yansongda\Pay\Gateways\Alipay;
/**
*
*/
* class WebGateway
*/
class WebGateway extends Alipay
{
/**
* [getMethod description]
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-10
*
* @return [type] [description]
*/
protected function getPayMethod() {
@ -19,8 +22,11 @@ class WebGateway extends Alipay
/**
* [getProductCode description]
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-10
*
* @return [type] [description]
*/
protected function getPayProductCode() {

View File

@ -1,16 +1,19 @@
<?php
<?php
namespace Yansongda\Pay\Gateways\Wechat;
/**
* 微信 - 公众号支付
*/
* 微信 - 公众号支付
*/
class AppGateway extends Wechat
{
/**
* 交易类型
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-15
*
* @return [type] [description]
*/
protected function getTradeType()
@ -20,9 +23,13 @@ class AppGateway extends Wechat
/**
* 对外支付
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-15
*
* @param array $config_biz [description]
*
* @return [type] [description]
*/
public function pay(array $config_biz = [])

View File

@ -1,16 +1,19 @@
<?php
<?php
namespace Yansongda\Pay\Gateways\Wechat;
/**
* 微信支付 - 扫码支付
*/
* 微信支付 - 扫码支付
*/
class ScanGateway extends Wechat
{
/**
* [getTradeType description]
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-15
*
* @return [type] [description]
*/
public function getTradeType()
@ -20,9 +23,13 @@ class ScanGateway extends Wechat
/**
* 对外支付
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-15
*
* @param array $config_biz [description]
*
* @return [type] [description]
*/
public function pay(array $config_biz = [])

View File

@ -1,16 +1,19 @@
<?php
<?php
namespace Yansongda\Pay\Gateways\Wechat;
/**
* 微信 - 公众号支付
*/
* 微信 - 公众号支付
*/
class MpGateway extends Wechat
{
/**
* 交易类型
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-15
*
* @return [type] [description]
*/
protected function getTradeType()
@ -20,9 +23,13 @@ class MpGateway extends Wechat
/**
* 对外支付
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-15
*
* @param array $config_biz [description]
*
* @return [type] [description]
*/
public function pay(array $config_biz = [])

View File

@ -1,12 +1,21 @@
<?php
<?php
namespace Yansongda\Pay\Gateways\Wechat;
/**
* 微信支付 - 刷卡支付
*/
* 微信支付 - 刷卡支付
*/
class PosGateway extends Wechat
{
/**
* [getTradeType description]
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-15
*
* @return [type] [description]
*/
public function getTradeType()
{
return 'JSAPI';

View File

@ -1,16 +1,19 @@
<?php
<?php
namespace Yansongda\Pay\Gateways\Wechat;
/**
* 微信支付 - 扫码支付
*/
* 微信支付 - 扫码支付
*/
class ScanGateway extends Wechat
{
/**
* [getTradeType description]
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-15
*
* @return [type] [description]
*/
public function getTradeType()
@ -20,16 +23,20 @@ class ScanGateway extends Wechat
/**
* 对外支付,采用 「模式二」 进行支付
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-15
*
* @param array $config_biz [description]
*
* @return string 微信支付扫码 URL
*/
public function pay(array $config_biz = [])
{
$this->config = array_merge($this->config, $config_biz);
$data = $this->preOrder(),
$data = $this->preOrder();
return $data['code_url'];
}

View File

@ -1,16 +1,19 @@
<?php
<?php
namespace Yansongda\Pay\Gateways\Wechat;
/**
* 微信支付 - H5 支付
*/
* 微信支付 - H5 支付
*/
class WapGateway extends Wechat
{
/**
* [getTradeType description]
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-15
*
* @return [type] [description]
*/
public function getTradeType()
@ -20,9 +23,13 @@ class WapGateway extends Wechat
/**
* 支付
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-15
*
* @param array $config_biz [description]
*
* @return [type] [description]
*/
public function pay(array $config_biz = [])

View File

@ -1,4 +1,4 @@
<?php
<?php
namespace Yansongda\Pay\Gateways\Wechat;
@ -9,34 +9,40 @@ use Yansongda\Pay\Exceptions\GatewayException;
use Yansongda\Pay\Exceptions\InvalidArgumentException;
/**
*
*/
* abstract class Wechat
*/
abstract class Wechat implements GatewayInterface
{
use HasHttpRequest;
/**
* [$preOrder_gateway description]
*
* @var string
*/
protected $preOrder_gateway = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
/**
* [$config description]
*
* @var [type]
*/
protected $config;
/**
* [$user_config description]
*
* @var [type]
*/
protected $user_config;
/**
* [__construct description]
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-14
*
* @param array $config [description]
*/
public function __construct(array $config)
@ -55,17 +61,24 @@ abstract class Wechat implements GatewayInterface
/**
* 对外支付接口
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-15
*
* @param array $cofnig_biz [description]
*
* @return [type] [description]
*/
abstract public function pay(array $config_biz = []);
/**
* 对外接口 - 退款
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-15
*
* @return [type] [description]
*/
public function refund(array $config_biz = [])
@ -75,8 +88,11 @@ abstract class Wechat implements GatewayInterface
/**
* 对外接口 - 关闭订单
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-15
*
* @return [type] [description]
*/
public function close(array $config_biz = [])
@ -86,10 +102,15 @@ abstract class Wechat implements GatewayInterface
/**
* 验证签名
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-15
*
* @param string $data 待验证 xml 数据
* @param string $sign 服务器返回的签名
* @param bool $sync is sync sign
*
* @return bool 是否相符
*/
public function verify($data, $sign = null, $sync = false)
@ -103,8 +124,11 @@ abstract class Wechat implements GatewayInterface
/**
* 预下单
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-15
*
* @return array 服务器返回结果数组
*/
protected function preOrder()
@ -130,9 +154,13 @@ abstract class Wechat implements GatewayInterface
/**
* 签名
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-15
*
* @param array $data 带签名数组
*
* @return string [description]
*/
protected function getSign($data)
@ -150,9 +178,13 @@ abstract class Wechat implements GatewayInterface
/**
* 将数组转换成 URL 格式
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-15
*
* @param array $data [description]
*
* @return string [description]
*/
protected function getSignContent($data)
@ -171,9 +203,13 @@ abstract class Wechat implements GatewayInterface
/**
* 生成随机字符串
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-14
*
* @param integer $length [description]
*
* @return [type] [description]
*/
protected function createNonceStr($length = 16) {
@ -188,9 +224,13 @@ abstract class Wechat implements GatewayInterface
/**
* 转化为 xml
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-14
*
* @param array $data 带转化数组
*
* @return string 转化后的xml字符串
*/
protected function toXml($data)
@ -214,9 +254,13 @@ abstract class Wechat implements GatewayInterface
/**
* xml 转化为 array
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-14
*
* @param string $xml xml字符串
*
* @return array 转化后的数组
*/
protected function fromXml($xml)

View File

@ -1,4 +1,4 @@
<?php
<?php
namespace Yansongda\Pay;
@ -6,32 +6,38 @@ use Yansongda\Pay\Support\Config;
use Yansongda\Pay\Exceptions\InvalidArgumentException;
/**
*
* class Pay
*/
class Pay
{
/**
* [$config description]
*
* @var [type]
*/
private $config;
/**
* [$dirvers description]
*
* @var [type]
*/
private $dirvers;
/**
* [$gateways description]
*
* @var [type]
*/
private $gateways;
/**
* [__construct description]
*
* @author JasonYan <me@yansongda.cn>
*
* @version 2017-07-29
*
* @param array $config [description]
*/
public function __construct(array $config = [])
@ -41,9 +47,13 @@ class Pay
/**
* [driver description]
*
* @author JasonYan <me@yansongda.cn>
*
* @version 2017-07-30
*
* @param [type] $driver [description]
*
* @return [type] [description]
*/
public function driver($driver)
@ -59,9 +69,13 @@ class Pay
/**
* [gateway description]
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-10
*
* @param string $gateway [description]
*
* @return [type] [description]
*/
public function gateway($gateway = 'web')
@ -77,9 +91,13 @@ class Pay
/**
* [createGateway description]
*
* @author yansongda <me@yansongda.cn>
*
* @version 2017-08-10
*
* @param [type] $gateway [description]
*
* @return [type] [description]
*/
private function createGateway($gateway)
@ -95,10 +113,14 @@ class Pay
/**
* [buildDriver description]
*
* @author JasonYan <me@yansongda.cn>
*
* @version 2017-07-30
* @param [type] $driver [description]
*
* @param [type] $driver [description]
* @param [type] $config [description]
*
* @return [type] [description]
*/
private function build($gateway)

View File

@ -27,10 +27,14 @@ class Config implements ArrayAccess
/**
* get a config
*
* @author JasonYan <me@yansongda.cn>
*
* @version 2017-07-28
*
* @param [type] $key [description]
* @param [type] $default [description]
*
* @return [type] [description]
*/
public function get($key = null, $default = null)
@ -57,9 +61,13 @@ class Config implements ArrayAccess
/**
* set a config
*
* @author JasonYan <me@yansongda.cn>
*
* @version 2017-07-29
*
* @param string $key [description]
*
* @param [type] $value [description]
*/
public function set(string $key, $value)
@ -91,9 +99,13 @@ class Config implements ArrayAccess
/**
* [offsetExists description]
*
* @author JasonYan <me@yansongda.cn>
*
* @version 2017-07-30
*
* @param [type] $offset [description]
*
* @return [type] [description]
*/
public function offsetExists($offset)
@ -103,9 +115,13 @@ class Config implements ArrayAccess
/**
* [offsetGet description]
*
* @author JasonYan <me@yansongda.cn>
*
* @version 2017-07-30
*
* @param [type] $offset [description]
*
* @return [type] [description]
*/
public function offsetGet($offset)
@ -115,10 +131,14 @@ class Config implements ArrayAccess
/**
* [offsetSet description]
*
* @author JasonYan <me@yansongda.cn>
*
* @version 2017-07-30
*
* @param [type] $offset [description]
* @param [type] $value [description]
*
* @return [type] [description]
*/
public function offsetSet($offset, $value)
@ -128,9 +148,13 @@ class Config implements ArrayAccess
/**
* [offsetUnset description]
*
* @author JasonYan <me@yansongda.cn>
*
* @version 2017-07-30
*
* @param [type] $offset [description]
*
* @return [type] [description]
*/
public function offsetUnset($offset)