Callback.php
8.6 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
<?php
namespace app\api\controller\wanlshop;
use think\View;
use app\common\controller\Api;
use addons\wanlshop\library\WanlChat\WanlChat;
use addons\wanlshop\library\WanlPay\WanlPay;
/**
* WanlShop 回调接口
*/
class Callback extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize();
}
/**
* 接收快递100推送消息
*
* @ApiSummary (WanlShop 快递接口-接收快递100推送消息)
* @ApiMethod (POST)
*
* @param string $status 物流状态 polling:监控中,shutdown:结束,abort:中止,updateall:重新推送
* @param array $lastResult 最新物流动态
*/
public function kuaidi()
{
//设置过滤方法
$this->request->filter(['strip_tags']);
if ($this->request->isPost()) {
$kuaidi = model('app\api\model\wanlshop\KuaidiSub');
$post = $this->request->post();
// 接收消息
try {
$param = json_decode($post["param"], true);
$status = $param['status']; // 状态 polling:监控中,shutdown:结束,abort:中止,updateall:重新推送
$message = $param['lastResult']['message']; // 消息体
$state = $param['lastResult']['state']; // 快递单当前状态,包括0在途,1揽收,2疑难,3签收,4退签,5派件,6退回,7转投
$ischeck = $param['lastResult']['ischeck']; // 是否签收标记
$nu = $param['lastResult']['nu']; // 快递单号
$com = $param['lastResult']['com']; // 快递公司编码
$data = $param['lastResult']['data']; // 数组,包含多个对象,每个对象字段如展开所示
// 查询快递是否存在
$express = $kuaidi->get(['express_no' => $nu]);
if($express){
// 判断来源
if($post["sign"] != strtoupper(md5($post["param"].$express['sign']))){
return json(["result" => false, "returnCode" => "405", "message" => "校验码错误"]);
}
// 更新数据
$express->message = $message;
$express->status = $status;
$express->state = $state;
$express->ischeck = $ischeck;
$express->com = $com;
$express->data = json_encode($data);
$express->save();
// 判断更新状态
if($express){
return json(["result" => true, "returnCode" => "200", "message" => "接收成功"]);
}
}else{
return json(["result" => false, "returnCode" => "404", "message" => "快递单号不存在"]);
}
} catch (Exception $e) {
return json(["result" => false, "returnCode" => "500", "message" => "服务器错误"]);
}
}
return json(["result" => false, "returnCode" => "500", "message" => "非正常访问"]);
}
/**
* 推流状态回调
*
* @ApiSummary (WanlShop 直播接口-推流状态回调)
* @ApiMethod (POST)
*
* @param string $action 回调状态 publish / publish_done
* @param string $ip 回调地址ip
* @param string $id 推流流名
* @param string $app 推流域名
* @param string $appname 推流app名
* @param string $time timestamp
* @param string $usrargs 用户参数
* @param string $node 内部节点ip
*/
public function push($id, $action)
{
$row = model('app\api\model\wanlshop\Live')->get(['liveid' => $id]);
$find = model('app\api\model\wanlshop\Find');
if($row){
if($action == 'publish'){
$this->sendLiveGroup($id, ['type' => 'publish']);
$row->save(['state' => 1]);
// 避免多次推流,检查是否存在多个
$count = $find->where('live_id', $row['id'])->count();
// 发布动态
if($count == 0){
// 关联商品
$goods = model('app\api\model\wanlshop\Goods')
->where('id','in',$row['goods_ids'])
->limit(2)
->select();
$image = [$row['image']];
foreach ($goods as $vo) {
$image[] = $vo['image'];
}
$find->save([
'shop_id' => $row['shop_id'],
'type' => 'live',
'goods_ids' => $row['goods_ids'],
'live_id' => $row['id'],
'content' => $row['content'],
'images' => implode(',', $image)
]);
}
}else if($action == 'publish_done'){
$this->sendLiveGroup($id, ['type' => 'publish_done']);
$row->save(['state' => 2]);
}
}else{
$this->error(__('没有找到相关推流'));
}
}
/**
* 录制文件回调
*
* @ApiSummary (WanlShop 直播接口-录制文件回调)
* @ApiMethod (POST)
*
* @param string $domain 回调状态 publish / publish_done
* @param string $app 回调地址ip
* @param string $stream 推流流名
* ------------------------------------
* @param string $event record_started/record_paused/record_resumed
*-------------------------------------
* @param string $uri 推流域名
* @param string $duration 推流app名
* @param string $start_time timestamp
* @param string $stop_time 用户参数
*/
public function record()
{
if ($this->request->isPost()) {
$event = $this->request->post('event');
$stream = $this->request->post('stream');
$uri = $this->request->post('uri');
if($event == 'record_started'){
// 录制开始
}else if($event == 'record_paused'){
// 录制暂停
}else if($event == 'record_resumed'){
// 录制继续
}else{
// 录制成功
if($uri && $stream){
$config = get_addon_config('wanlshop');
$live = model('app\api\model\wanlshop\Live');
$live->save(['recordurl' => $config['live']['liveCnd'].'/'.$uri],['liveid' => $stream]);
}else{
$this->error(__('录制失败'));
}
}
}
$this->error(__('非正常访问'));
}
/**
* 安全审核
*
* @ApiSummary (WanlShop 直播接口-安全审核)
* @ApiMethod (POST)
*
* @param string $DomainName 用户域名
* @param string $AppName App名
* @param string $StreamName 流名
* @param string $OssEndpoint 存储对象 Endpoint
* @param string $OssBucket 存储对象的 Bucket
* @param string $OssObject 存储对象的文件名
* @param array $Result 参数
*/
public function detectporn($StreamName, $Result)
{
$res = $Result[0]['Result'][0];
if($res['Suggestion'] == 'block'){ // 违规
$live = model('app\api\model\wanlshop\Live')->get(['liveid' => $StreamName]);
model('app\api\model\wanlshop\Find')->where(['live_id' => $live['id']])->delete();
$live->save(['gestion' => $res['Scene'], 'state' => 3]);
// 封禁直播间
$this->sendLiveGroup($StreamName, ['type' => 'ban']);
}else if($res['Suggestion'] == 'review'){ // 直播间存在违规
$this->sendLiveGroup($StreamName, [
'type' => 'review',
'text' => '直播间存在违规,请主播及时更正'
]);
}
}
/**
* 支付成功回调
*
* @ApiSummary (WanlShop 支付接口-支付成功回调)
* @ApiMethod (POST)
*
*/
public function notify($type)
{
if(empty($type)){
$this->error(__('非正常访问'));
}
$wanlpay = new WanlPay($type);
$result = $wanlpay->notify();
if($result['code'] == 200){
return $result['msg'];
}else{
\Think\Log::write($result, 'debug');
$this->error($result['msg']);
}
}
/**
* 支付成功回调
*
* @ApiSummary (WanlShop 支付接口-支付成功回调)
* @ApiMethod (POST)
*
*/
public function notify_recharge($type)
{
if(empty($type)){
$this->error(__('非正常访问'));
}
$wanlpay = new WanlPay($type);
$result = $wanlpay->notify_recharge();
if($result['code'] == 200){
return $result['msg'];
}else{
\Think\Log::write($result, 'debug');
$this->error($result['msg']);
}
}
/**
* 支付成功返回
*
* @ApiSummary (WanlShop 支付接口-支付成功返回)
* @ApiMethod (POST)
*
*/
public function return($type)
{
if(empty($type)){
$this->error(__('非正常访问'));
}
$view = new View();
$wanlpay = new WanlPay($type);
$config = get_addon_config('wanlshop');
$view->row = $wanlpay->return();
$view->config = $config['h5'];
return $view->fetch('index@wanlshop/page/success');
}
/**
* 发送直播群组消息
* 内部方法
*/
private function sendLiveGroup($group, $message)
{
$wanlchat = new WanlChat();
$wanlchat->sendGroup($group, [
'type' => 'live',
'group' => $group,
'form' => [
'id' => 0,
'nickname' => '系统'
],
'message' => $message,
'online' => 0,
'like' => 0
]);
}
}