Notify.php
5.2 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php
namespace app\mobile\controller;
use think\Db;
use app\common\controller\Api;
use app\mobile\model\CourseOrder;
use app\mobile\model\SecretOrder;
use app\mobile\model\ScoreOrder;
use app\mobile\model\PackageOrder;
use addons\qiniu\library\Auth;
use app\common\model\Attachment;
/**
* 异步接口
* @ApiInternal
*/
class Notify extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize();
}
/**
* 课程
*/
public function notifyCourse()
{
$paytype = $this->request->param('paytype');
$pay = \addons\epay\library\Service::checkNotify($paytype);
if (!$pay) {
echo '签名错误';
return;
}
$data = $pay->verify();
try {
$payamount = $paytype == 'alipay' ? $data['total_amount'] : $data['total_fee'] / 100;
$out_trade_no = $data['out_trade_no'];
// 处理订单逻辑
$order = CourseOrder::get(['order_sn'=>$out_trade_no,'pay_price'=>$payamount,'pay_type'=>$paytype]);
if($order && $order['pay_status'] != '1'){
$order->save(['pay_status'=>'1','pay_time'=>time()]);
}
} catch (Exception $e) {
}
echo $pay->success();
}
/**
* 密卷
*/
public function notifySecret()
{
$paytype = $this->request->param('paytype');
$pay = \addons\epay\library\Service::checkNotify($paytype);
if (!$pay) {
echo '签名错误';
return;
}
$data = $pay->verify();
try {
$payamount = $paytype == 'alipay' ? $data['total_amount'] : $data['total_fee'] / 100;
$out_trade_no = $data['out_trade_no'];
// 处理订单逻辑
$order = SecretOrder::get(['order_sn'=>$out_trade_no,'pay_price'=>$payamount,'pay_type'=>$paytype]);
if($order && $order['pay_status'] != '1'){
$order->save(['pay_status'=>'1','pay_time'=>time()]);
}
} catch (Exception $e) {
}
echo $pay->success();
}
/**
* 积分
*/
public function notifyScore()
{
$paytype = $this->request->param('paytype');
$pay = \addons\epay\library\Service::checkNotify($paytype);
if (!$pay) {
echo '签名错误';
return;
}
$data = $pay->verify();
try {
$payamount = $paytype == 'alipay' ? $data['total_amount'] : $data['total_fee'] / 100;
$out_trade_no = $data['out_trade_no'];
// 处理订单逻辑
$order = ScoreOrder::get(['order_sn'=>$out_trade_no,'pay_price'=>$payamount,'pay_type'=>$paytype]);
if($order && $order['pay_status'] != '1'){
$order->save(['pay_status'=>'1','pay_time'=>time()]);
// 增加积分
\app\common\model\User::score($order['score'],$order['user_id'],'充值积分');
}
} catch (Exception $e) {
}
echo $pay->success();
}
/**
* 企业套餐
*/
public function notifyPackage()
{
$paytype = $this->request->param('paytype');
$pay = \addons\epay\library\Service::checkNotify($paytype);
if (!$pay) {
echo '签名错误';
return;
}
$data = $pay->verify();
try {
$payamount = $paytype == 'alipay' ? $data['total_amount'] : $data['total_fee'] / 100;
$out_trade_no = $data['out_trade_no'];
// 处理订单逻辑
$order = PackageOrder::get(['order_sn'=>$out_trade_no,'pay_price'=>$payamount,'pay_type'=>$paytype]);
if($order && $order['pay_status'] != '1'){
$order->save(['pay_status'=>'1','pay_time'=>time()]);
}
} catch (Exception $e) {
}
echo $pay->success();
}
/**
* 七牛云音频转码通知回调
* @ApiInternal
*/
public function notifyQiniuAvthumb()
{
if($this->request->isPost()) {
$arr = $this->request->param();
// 判断七牛云回调code是否为完成
if(isset($arr['code']) && $arr['code'] == 0) {
$url = '/' . $arr['items'][0]['key'];
$info = Attachment::get(['url'=>$url]);
if(!$info){
$params = array(
'admin_id' => 0,
'user_id' => 0,
'filesize' => 0,
'imagewidth' => 0,
'imageheight' => 0,
'imagetype' => 'pcm',
'imageframes' => 0,
'mimetype' => 'application/octet-stream',
'extparam' => '',
'url' => $url,
'uploadtime' => time(),
'storage' => 'qiniu'
);
Attachment::create($params);
}
return json(['ret' => 'success', 'code' => 1, 'data' => ['url' => $url]]);
}
return json(['ret' => 'failed']);
}
}
}