Skip to content

Commit a37ebfa

Browse files
authored
Merge pull request #55 from MengDianYun/master
新增微信普通红包,裂变红包
2 parents 256a5f2 + 7d11f1d commit a37ebfa

File tree

3 files changed

+262
-0
lines changed

3 files changed

+262
-0
lines changed

README.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,101 @@ $config_biz = [
871871
类型:array
872872
说明:返回用于 支付结果 的数组。具体请 [参考这里](https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_2)
873873

874+
### 13、微信 - 发放裂变红包
874875

876+
#### 最小配置参数
877+
```php
878+
<?php
879+
$config = [
880+
'wechat' => [
881+
'app_id'=>'wxaxxxxxxxx',
882+
'mch_id' => '1442222202',
883+
'key' => 'ddddddddddddddd',
884+
'cert_client' => 'D:\php\xxx\application\wxpay\cert\apiclient_cert.pem',
885+
'cert_key' => 'D:\php\xxx\application\wxpay\cert\apiclient_key.pem',
886+
],
887+
];
888+
889+
$config_biz = [
890+
'wxappid'=>'wxaxxxxxxxx',
891+
'mch_billno' => 'hb'.time(),
892+
'send_name'=>'萌点云科技',//商户名称
893+
're_openid'=>'ogg5JwsssssssssssCdXeD_S54',//用户openid
894+
'total_amount' =>333, // 付款金额,单位分
895+
'wishing'=>'提前祝你狗年大吉',//红包祝福语
896+
'client_ip'=>'192.168.0.1',//调用接口的机器Ip地址
897+
'total_num'=>'3',//红包发放总人数
898+
'act_name'=>'提前拜年',//活动名称
899+
'remark'=>'提前祝你狗年大吉,苟富贵勿相忘!', //备注
900+
'amt_type'=>'ALL_RAND',//ALL_RAND—全部随机,商户指定总金额和红包发放总人数,由微信支付随机计算出各红包金额
901+
];
902+
903+
$pay = new Pay($config);
904+
try
905+
{
906+
$res= $pay->driver('wechat')->gateway('groupredpack')->pay($config_biz);
907+
908+
}catch (Exception $e){
909+
910+
}
911+
912+
```
913+
914+
#### 所有配置参数
915+
具体请看 [官方文档](https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_5&index=4)
916+
917+
#### 返回值
918+
- pay()
919+
类型:array
920+
说明:返回用于 支付结果 的数组。具体请 [参考这里](https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_5&index=4)
921+
922+
923+
### 14、微信 - 发放普通红包
924+
925+
#### 最小配置参数
926+
```php
927+
<?php
928+
$config = [
929+
'wechat' => [
930+
'app_id'=>'wxaxxxxxxxx',
931+
'mch_id' => '1442222202',
932+
'key' => 'ddddddddddddddd',
933+
'cert_client' => 'D:\php\xxx\application\wxpay\cert\apiclient_cert.pem',
934+
'cert_key' => 'D:\php\xxx\application\wxpay\cert\apiclient_key.pem',
935+
],
936+
];
937+
938+
$config_biz = [
939+
'wxappid'=>'wxaxxxxxxxx',
940+
'mch_billno' => 'hb'.time(),
941+
'send_name'=>'萌点云科技',//商户名称
942+
're_openid'=>'ogg5JwsssssssssssCdXeD_S54',//用户openid
943+
'total_amount' =>100, // 付款金额,单位分
944+
'wishing'=>'提前祝你狗年大吉',//红包祝福语
945+
'client_ip'=>'192.168.0.1',//调用接口的机器Ip地址
946+
'total_num'=>'1',//红包发放总人数
947+
'act_name'=>'提前拜年',//活动名称
948+
'remark'=>'提前祝你狗年大吉,苟富贵勿相忘!', //备注
949+
];
950+
951+
$pay = new Pay($config);
952+
try
953+
{
954+
$res= $pay->driver('wechat')->gateway('redpack')->pay($config_biz);
955+
956+
}catch (Exception $e){
957+
958+
}
959+
960+
```
961+
962+
#### 所有配置参数
963+
具体请看 [官方文档](https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_4&index=3)
964+
965+
#### 返回值
966+
- pay()
967+
类型:array
968+
说明:返回用于 支付结果 的数组。具体请 [参考这里](https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_4&index=3)
875969
## 代码贡献
876970
由于测试及使用环境的限制,本项目中只开发了「支付宝」和「微信支付」的相关支付网关。
877971

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
3+
/**
4+
* 发放裂变红包
5+
* Class GroupredpackGateway
6+
* Date: 2017/12/21
7+
* Time: 19:23
8+
* Com:萌点云科技(深圳)有限公司.
9+
*
10+
* Author:陈老司机
11+
*
12+
* Email:690712575@qq.com
13+
*/
14+
15+
namespace Yansongda\Pay\Gateways\Wechat;
16+
17+
use Yansongda\Pay\Exceptions\GatewayException;
18+
use Yansongda\Pay\Exceptions\InvalidArgumentException;
19+
20+
class GroupredpackGateway extends Wechat
21+
{
22+
/**
23+
* @var string
24+
*/
25+
protected $gateway_transfer = 'mmpaymkttransfers/sendgroupredpack';
26+
27+
/**
28+
* pay a order.
29+
*
30+
* @author yansongda <me@yansongda.cn>
31+
*
32+
* @param array $config_biz
33+
*
34+
* @return mixed
35+
*/
36+
public function pay(array $config_biz = [])
37+
{
38+
if (is_null($this->user_config->get('app_id'))) {
39+
throw new InvalidArgumentException('Missing Config -- [app_id]');
40+
}
41+
unset($this->config['sign_type']);
42+
unset($this->config['trade_type']);
43+
unset($this->config['notify_url']);
44+
unset($this->config['app_id']);
45+
unset($this->config['appid']);
46+
$this->config = array_merge($this->config, $config_biz);
47+
$this->config['sign'] = $this->getSign($this->config);
48+
$data = $this->fromXml($this->post(
49+
$this->endpoint.$this->gateway_transfer,
50+
$this->toXml($this->config),
51+
[
52+
'cert' => $this->user_config->get('cert_client', ''),
53+
'ssl_key' => $this->user_config->get('cert_key', ''),
54+
]
55+
));
56+
if (!isset($data['return_code']) || $data['return_code'] !== 'SUCCESS' || $data['result_code'] !== 'SUCCESS') {
57+
$error = 'getResult error:'.$data['return_msg'];
58+
$error .= isset($data['err_code_des']) ? ' - '.$data['err_code_des'] : '';
59+
}
60+
61+
if (isset($error)) {
62+
throw new GatewayException(
63+
$error,
64+
20000,
65+
$data);
66+
}
67+
68+
return $data;
69+
}
70+
71+
/**
72+
* get trade type config.
73+
*
74+
* @author yansongda <me@yansongda.cn>
75+
*
76+
* @return string
77+
*/
78+
protected function getTradeType()
79+
{
80+
return '';
81+
}
82+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
3+
/**
4+
* 发放普通红包
5+
* Class RedPackGateway
6+
* Date: 2017/12/21
7+
* Time: 19:23
8+
* Com:萌点云科技(深圳)有限公司.
9+
*
10+
* Author:陈老司机
11+
*
12+
* Email:690712575@qq.com
13+
*/
14+
15+
namespace Yansongda\Pay\Gateways\Wechat;
16+
17+
use Yansongda\Pay\Exceptions\GatewayException;
18+
use Yansongda\Pay\Exceptions\InvalidArgumentException;
19+
20+
class RedpackGateway extends Wechat
21+
{
22+
/**
23+
* @var string
24+
*/
25+
protected $gateway_transfer = 'mmpaymkttransfers/sendredpack';
26+
27+
/**
28+
* pay a order.
29+
*
30+
* @author yansongda <me@yansongda.cn>
31+
*
32+
* @param array $config_biz
33+
*
34+
* @return mixed
35+
*/
36+
public function pay(array $config_biz = [])
37+
{
38+
if (is_null($this->user_config->get('app_id'))) {
39+
throw new InvalidArgumentException('Missing Config -- [app_id]');
40+
}
41+
unset($this->config['sign_type']);
42+
unset($this->config['trade_type']);
43+
unset($this->config['notify_url']);
44+
unset($this->config['app_id']);
45+
unset($this->config['appid']);
46+
47+
$this->config = array_merge($this->config, $config_biz);
48+
49+
$this->config['sign'] = $this->getSign($this->config);
50+
51+
$data = $this->fromXml($this->post(
52+
$this->endpoint.$this->gateway_transfer,
53+
$this->toXml($this->config),
54+
[
55+
'cert' => $this->user_config->get('cert_client', ''),
56+
'ssl_key' => $this->user_config->get('cert_key', ''),
57+
]
58+
));
59+
60+
if (!isset($data['return_code']) || $data['return_code'] !== 'SUCCESS' || $data['result_code'] !== 'SUCCESS') {
61+
$error = 'getResult error:'.$data['return_msg'];
62+
$error .= isset($data['err_code_des']) ? ' - '.$data['err_code_des'] : '';
63+
}
64+
65+
if (isset($error)) {
66+
throw new GatewayException(
67+
$error,
68+
20000,
69+
$data);
70+
}
71+
72+
return $data;
73+
}
74+
75+
/**
76+
* get trade type config.
77+
*
78+
* @author yansongda <me@yansongda.cn>
79+
*
80+
* @return string
81+
*/
82+
protected function getTradeType()
83+
{
84+
return '';
85+
}
86+
}

0 commit comments

Comments
 (0)