WxPay.php
3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
defined('IN_IA') or exit('Access Denied');
require_once IA_ROOT . '/addons/zh_cjdianc/inc/config.php';
require_once IA_ROOT . '/addons/zh_cjdianc/inc/wxlib/WxPay.Api.php';
require_once IA_ROOT . '/addons/zh_cjdianc/inc/class/Order.php';
class WxPay
{
//订单退款
public static function orderRefund($order_id, $orderType = Order::TYPE_TAKE_OUT)
{
global $_W, $_GPC;
load()->model('account');
load()->func('communication');
$fee = 0;
if (Order::TYPE_TAKE_OUT == $orderType) {
$refund_order = pdo_get('cjdc_order', array('id' => $order_id));
if ($refund_order) {
$fee = $refund_order['money'] * 100;
}
}
if (Order::TYPE_GROUP == $orderType) {
$refund_order = pdo_get('cjdc_grouporder', array('dispatch_order_id' => $order_id));
if ($refund_order) {
$fee = $refund_order['pay_price'] * 100;
}
}
if (empty($refund_order)) {
return null;
}
$out_trade_no = $refund_order['code'];
$refundNo = $refund_order['order_num'];
$res = pdo_get('cjdc_pay', array('uniacid' => $_W['uniacid']));
$system = pdo_get('cjdc_system', array('uniacid' => $_W['uniacid']));
$WxPayApi = new WxPayApi();
$input = new WxPayRefund();
$store = pdo_get('cjdc_store', array('id' => $refund_order['store_id']));
$res2 = pdo_get('cjdc_service_pay', array('uniacid' => $_W['uniacid']));
if ($res2['is_open'] == 1 and $store['store_mchid']) {
//服务商退款
$certPaths = Config::getServiceCertPaths($_W['uniacid']);
$path_cert = $certPaths[0];
$path_key = $certPaths[1];
$appid = $res2['appid'];
$key = $res2['wxkey'];
$mchid = $res2['mchid'];
$sub_appid = $res['appid'];
$sub_mch_id = $store['store_mchid'];
$input->SetSub_Appid($sub_appid);
$input->SetSub_Mch_id($sub_mch_id);
} else {
$paths = Config::getCertPaths($_W['uniacid']);
$path_cert = $paths[0];
$path_key = $paths[1];
$appid = $system['appid'];
$key = $res['wxkey'];
$mchid = $res['mchid'];
}
$input->SetAppid($appid);
$input->SetMch_id($mchid);
$input->SetOp_user_id($mchid);
$input->SetRefund_fee($fee);
$input->SetTotal_fee($fee);
// $input->SetTransaction_id($refundid);
$input->SetOut_refund_no($refundNo);
$input->SetOut_trade_no($out_trade_no);
$result = $WxPayApi->refund($input, 6, $path_cert, $path_key, $key);
return $result;
}
/**
* 企业账号转个人钱包
* @param $uniacId
* @param $withdrawalList
* @return array
* @throws WxPayException
*/
public static function wxTransfer($uniacId, $withdrawalList)
{
$store = pdo_get('cjdc_store', array('id' => $withdrawalList['store_id']));
$user = pdo_get('cjdc_user', array('id' => $store['user_id']));
$system = pdo_get('cjdc_system', array('uniacid'=> $uniacId));
$psystem = pdo_get('cjdc_pay', array('uniacid'=> $uniacId));
$paths = Config::getCertPaths($uniacId);
$wxPayApi = new WxPayApi();
$input = new WxPayTransfer();
$input->SetMchAppId($system['appid']);
$input->SetMchId($psystem['mchid']);
$input->SetPartnerTradeNo('A'.time().rand(11111,99999));
$input->SetOpenId($user['openid']);
$input->SetCheckName('NO_CHECK');
$input->SetReUserName($withdrawalList['name']);
$input->SetAmount($withdrawalList['sj_cost']*100);
$input->SetDesc('提现打款');
$input->SetSpbilCreateIp($psystem['ip']);
$result = $wxPayApi->transferTo($input, 6, $paths[0], $paths[1], $psystem['wxkey']);
return $result;
}
}