PayController.php
2.7 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
<?php
namespace app\portal\controller;
use cmf\controller\HomeBaseController;
use think\Db;
use think\Log;
use think\Validate;
/**
* 微信支付,退款,提现DEMO
* Class PayController
* @package app\portal\controller
*/
class PayController extends HomeBaseController
{
/**
* 微信支付
*/
public function index(){
}
/**
* 支付回调
*/
public function notify(){
}
/**
* 退款
* @throws \WxPayException
*/
public function refund(){
$param = $this->request->param();
$signature = $param['s'];
$arithmetic['timeStamp']= $param['t'];
$arithmetic['randomStr']= $param['r'];
$arithmetic['orderSn']= $param['o'];
$str = arithmetic($arithmetic);
if($str != $signature){
$this->error('签名验证失败');
}
/*微信退款*/
require_once EXTEND_PATH."WxpayAPI/lib/WxPay.Api.php";
require_once EXTEND_PATH."WxpayAPI/example/log.php";
if(isset($info["transaction_id"]) && empty($info["transaction_id"])){
$transaction_id = $info["transaction_id"];
$total_fee = $info["real_price"]*100;
$refund_fee = $info["real_price"]*100;
$input = new \WxPayRefund();
$input->SetTransaction_id($transaction_id);
$input->SetTotal_fee($total_fee);
$input->SetRefund_fee($refund_fee);
$input->SetOut_refund_no(\WxPayConfig::MCHID.date("YmdHis"));
$input->SetOp_user_id(\WxPayConfig::MCHID);
$ret=\WxPayApi::refund($input);
if($ret['result_code']=='SUCCESS'){
//todo 退款成功处理
$this->success('退款成功');
}else{
$this->error("退款失败:".$ret['err_code_des']);
}
}else{
$this->error('缺少退款标识');
}
}
/**
* 提现
*/
public function withdraw_cash(){
$param = $this->request->param();
$signature = $param['s'];
$arithmetic['timeStamp']= $param['t'];
$arithmetic['randomStr']= $param['r'];
$arithmetic['orderSn']= $param['o'];
$str = arithmetic($arithmetic);
if($str != $signature){
$this->error('签名验证失败');
}
$price=1;
$openid='';
$merch=new \MerchPay();
$trade_no = cmf_get_order_sn();
$res=$merch->pay($openid,$trade_no,$price,'提现');
if($res['result_code']=='SUCCESS'){
//todo 提现成功处理
}else{
$this->error('操作失败:'.$res['return_msg']);
}
}
}