Notify.php
4.1 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
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2019/11/27
* Time: 15:59
*/
namespace app\api\controller;
use app\common\controller\Api;
use EasyWeChat\Factory;
use function GuzzleHttp\Promise\inspect;
use think\Db;
use app\admin\model\User;
use think\Log;
use fast\Http;
use think\Validate;
use Exception;
use function EasyWeChat\Kernel\Support\generate_sign;
use app\nsms\sendAPI;
class Notify extends Api
{
protected $noNeedLogin = ['picOrderNotify'];
//图片支付订单结果通知(无需调用)
public function picOrderNotify(){
$config = config('verify.wx_pay');
$app = Factory::payment($config);
$response = $app->handlePaidNotify(function($message, $fail){
//return_code 表示通信状态
if ($message['return_code'] === 'SUCCESS') {
if ($message['result_code'] === 'SUCCESS') {
//支付成功,更新订单状态
$toporder['status'] = 2;
$toporder['paytime'] = time();
$data = Db::name('order')->where('id',$message['out_trade_no'])->find();
$pic_id = explode(',',$data['pic_id']);
$video_id = unserialize($data['video_id']);
$user = Db::name('user')->where('id',$data['user_id'])->find();
$mobile = $user['mobile'];
$str = "【仁甲看见】";
if(!empty($pic_id)){
foreach ($pic_id as $key => $v){
$pic = Db::name('pic')->field('id,buy_num')->where('id',$v)->find();
Db::name('pic')->where('id',$pic['id'])->update(['buy_num'=>$pic['buy_num']+1]);
}
foreach ($pic_id as $key => $v){
$pic = Db::name('pic')->field('id,title,url,code')->where('id',$v)->find();
$str .= "图片标题:$pic[title],云盘地址:$pic[url],提取码:$pic[code],";
}
}
if(!empty($video_id)){
foreach ($video_id as &$val){
if($val['attr'] == 1){
$val['attr'] = '2k';
}elseif ($val['attr'] == 2){
$val['attr'] = '4k';
}else{
$val['attr'] = '8k';
}
}
foreach ($video_id as $k=>$v){
if($v['attr'] == '4k'){
$video = Db::name('video')->field('id,title,four_url,four_code')->where('id',$v['id'])->find();
$str .= "视频标题:$video[title],云盘地址:$video[four_url],提取码:$video[four_code]";
}elseif ($v['attr'] == '2k'){
$video = Db::name('video')->field('id,title,two_url,two_code')->where('id',$v['id'])->find();
$str .= "视频标题:$video[title],云盘地址:$video[two_url],提取码:$video[two_code]";
}elseif ($v['attr'] == '8k'){
$video = Db::name('video')->field('id,title,eight_url,eight_code')->where('id',$v['id'])->find();
$str .= "视频标题:$video[title],云盘地址:$video[eight_url],提取码:$video[eight_code]";
}
}
}
//发送短信
if(!empty($mobile)){
$result = $this->sms($mobile,$str);
}
}else{
//支付失败
$toporder['status'] = 1;
}
}else{
return $fail('通信失败,请稍后再通知我');
}
Db::name('order')->where('num',$message['out_trade_no'])->update($toporder);
return true; // 返回处理完成
});
$response->send();
}
}