Skip to content

Commit

Permalink
企业付款
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue committed Jan 8, 2018
1 parent 8b48c7b commit 573e712
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 9 deletions.
2 changes: 2 additions & 0 deletions zh-CN/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
- [通知](/docs/{{version}}/{{lang}}/payment/notify)
- [红包](/docs/{{version}}/{{lang}}/payment/redpack)
- [JSSDK](/docs/{{version}}/{{lang}}/payment/jssdk)
- [企业付款](/docs/{{version}}/{{lang}}/payment/transfer)
- [撤销订单](/docs/{{version}}/{{lang}}/payment/reverse)
- [安全工具](/docs/{{version}}/{{lang}}/payment/security)

- ## 小程序
- [小程序码](/docs/{{version}}/{{lang}}/mini-program/app_code)
Expand Down
2 changes: 1 addition & 1 deletion zh-CN/official-account/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ return [

/**
* 接口请求相关配置,超时时间等,具体可用参数请参考:
* http://docs.guzzlephp.org/en/stable/request-options.html
* http://docs.guzzlephp.org/en/stable/request-config.html
*
* - retries: 重试次数,默认 1,指定当 http 请求失败时重试的次数。
* - retry_delay: 重试延迟间隔(单位:ms),默认 500
Expand Down
4 changes: 2 additions & 2 deletions zh-CN/payment/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
```php
use EasyWeChat\Factory;

$options = [
$config = [
// 必要配置
'app_id' => 'xxxx',
'mch_id' => 'your-mch-id',
Expand All @@ -22,7 +22,7 @@ $options = [
'notify_url' => '默认的订单回调地址', // 你也可以在下单时单独设置来想覆盖它
];

$app = Factory::payment($options);
$app = Factory::payment($config);
```

### 服务商
Expand Down
4 changes: 2 additions & 2 deletions zh-CN/payment/jssdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ JSSDK 模块用于生成调起微信支付以及共享收货地址的调用所
```php
use EasyWeChat\Factory;

$options = [
$config = [
// 前面的appid什么的也得保留哦
'app_id' => 'xxxx',
'mch_id' => 'your-mch-id',
Expand All @@ -21,7 +21,7 @@ $options = [
// ...
];

$payment = Factory::payment($options);
$payment = Factory::payment($config);

$jssdk = $payment->jssdk;
```
Expand Down
4 changes: 2 additions & 2 deletions zh-CN/payment/redpack.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
```php
use EasyWeChat\Factory;

$options = [
$config = [
'app_id' => 'you-app-id',
'mch_id' => 'your-mch-id',
'key' => 'key-for-signature',
Expand All @@ -19,7 +19,7 @@ $options = [
// ...
];

$payment = Factory::payment($options);
$payment = Factory::payment($config);

$redpack = $payment->redpack;
```
Expand Down
4 changes: 2 additions & 2 deletions zh-CN/payment/refund.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

```php
// 参数分别为:微信订单号、商户退款单号、订单金额、退款金额、其他参数
$app->refund->byTransactionId(string $transactionId, string $refundNumber, int $totalFee, int $refundFee, array $options = []);
$app->refund->byTransactionId(string $transactionId, string $refundNumber, int $totalFee, int $refundFee, array $config = []);

// Example:
$result = $app->refund->byTransactionId('transaction-id-xxx', 'refund-no-xxx', 10000, 10000, [
Expand All @@ -27,7 +27,7 @@ $result = $app->refund->byTransactionId('transaction-id-xxx', 'refund-no-xxx', 1

```php
// 参数分别为:商户订单号、商户退款单号、订单金额、退款金额、其他参数
$app->refund->byOutTradeNumber(string $number, string $refundNumber, int $totalFee, int $refundFee, array $options = []);
$app->refund->byOutTradeNumber(string $number, string $refundNumber, int $totalFee, int $refundFee, array $config = []);

// Example:
$result = $app->refund->byOutTradeNumber('out-trade-no-xxx', 'refund-no-xxx', 20000, 1000, [
Expand Down
44 changes: 44 additions & 0 deletions zh-CN/payment/security.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# 安全与风控

## 获取 RSA 公钥

```php
$result = $app->security->getPublicKey();

// 存成文件

file_put_contents('./public.pem', $result);
```

将会得到 PKCS#1 格式密钥:

```
-----BEGIN RSA PUBLIC KEY-----
MIIBCgKCAQEArT82k67xybiJS9AD8nNAeuDYdrtCRaxkS6cgs8L9h83eqlDTlrdw
zBVSv5V4imTq/URbXn4K0V/KJ1TwDrqOI8hamGB0fvU13WW1NcJuv41RnJVua0QA
lS3tS1JzOZpMS9BEGeFvyFF/epbi/m9+2kUWG94FccArNnBtBqqvFncXgQsm98JB
3a62NbS1ePP/hMI7Kkz+JNMyYsWkrOUFDCXAbSZkWBJekY4nGZtK1erqGRve8Jbx
TWirAm/s08rUrjOuZFA21/EI2nea3DidJMTVnXVPY2qcAjF+595shwUKyTjKB8v1
REPB3hPF1Z75O6LwuLfyPiCrCTmVoyfqjwIDAQAB
-----END RSA PUBLIC KEY-----
```

使用 OpenSSL 转换 PKCS#1PKCS#8 格式密钥:

```shell
openssl rsa -RSAPublicKey_in -in public.pem -out public.pem
```

PKCS#8 格式密钥:

```
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArT82k67xybiJS9AD8nNA
euDYdrtCRaxkS6cgs8L9h83eqlDTlrdwzBVSv5V4imTq/URbXn4K0V/KJ1TwDrqO
I8hamGB0fvU13WW1NcJuv41RnJVua0QAlS3tS1JzOZpMS9BEGeFvyFF/epbi/m9+
lkUWG94FccArNnBtBqqvFncXgQsm98JB3a42NbS1ePP/hMI7Kkz+JNMyYsWkrOUF
DCXAbSZkWBJekY4nGZtK1erqGRve8JbxTWirAm/s08rUrjOuZFA21/EI2nea3Did
JMTVnXVPY2qcAjF+595shwUKyTjKB8v1REPB3hPF1Z75O6LwuLfyPiCrCTmVoyfq
jwIDAQAB
-----END PUBLIC KEY-----
```
82 changes: 82 additions & 0 deletions zh-CN/payment/transfer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# 企业付款

该模块需要用到双向证书,请参考:https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=4_3

## 企业付款到用户零钱

```php
$app->transfer->toBalance([
'partner_trade_no' => '1233455', // 商户订单号,需保持唯一性(只能是字母或者数字,不能包含有符号)
'openid' => 'oxTWIuGaIt6gTKsQRLau2M0yL16E',
'check_name' => 'FORCE_CHECK', // NO_CHECK:不校验真实姓名, FORCE_CHECK:强校验真实姓名
're_user_name' => '王小帅', // 如果 check_name 设置为FORCE_CHECK,则必填用户真实姓名
'amount' => 10000, // 企业付款金额,单位为分
'desc' => '理赔', 企业付款操作说明信息。必填
]);
```

## 查询付款到零钱的订单

```php
$partnerTradeNo = 1233455;
$app->transfer->queryBankCardOrder($partnerTradeNo);
```


## 企业付款到银行卡

企业付款到银行卡需要对银行卡号与姓名进行 RSA 加密,所以这里需要先下载 RSA 公钥到本地(服务器),我们提供了一个命令行工具:[EasyWeChat/console](https://github.com/EasyWeChat/console),请使用 composer 安装完成。

然后,在项目根目录执行以下命令下载公钥:

```shell
$ ./vendor/bin/easywechat payment:rsa_public_key \
--mch_id=14339221228 \
--api_key=36YTbDmLgyQ52noqdxgwGiYy \
--cert_path=/Users/overtrue/www/demo/apiclient_cert.pem \
--key_path=/Users/overtrue/www/demo/apiclient_key.pem
```

将会在当前目录生成一个 `./public-14339221228.pem` 文件,你可以将它移动到敏感目录,然后在支付配置文件中加如以下选项:

```php
use EasyWeChat\Factory;

$config = [
// 必要配置
'app_id' => 'xxxx',
'mch_id' => 'your-mch-id',
'key' => 'key-for-signature', // API 密钥

// 如需使用敏感接口(如退款、发送红包等)需要配置 API 证书路径(登录商户平台下载 API 证书)
'cert_path' => '/path/to/your/cert.pem', // XXX: 绝对路径!!!!
'key_path' => '/path/to/your/key', // XXX: 绝对路径!!!!

// 将上面得到的公钥存放路径填写在这里
'rsa_public_key_path' => '/path/to/your/rsa/publick/key/public-14339221228.pem',

'notify_url' => '默认的订单回调地址', // 你也可以在下单时单独设置来想覆盖它
];

$app = Factory::payment($config);
```

```php
$result = $app->transfer->toBankCard([
'partner_trade_no' => '1229222022',
'enc_bank_no' => '6214830901234564', // 银行卡号
'enc_true_name' => '安正超', // 银行卡对应的用户真实姓名
'bank_code' => '1001', // 银行编号
'amount' => 100, // 单位:分
'desc' => '测试',
]);

```

## 查询付款到银行卡的订单

```php
$partnerTradeNo = 1233455;
$app->transfer->queryBankCardOrder($partnerTradeNo);
```

0 comments on commit 573e712

Please sign in to comment.