WechatSendMessage.php
7.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
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
<?php
namespace app\common\library;
use EasyWeChat\Factory;
/**
* 微信公众号-发送模版消息
*/
class WechatSendMessage
{
/**
* 发送一次
*
*/
public static function sendMessage($project, $openid, $keyword3)
{
$config = config('wechat.official_account');
$app = Factory::officialAccount($config);
$re = [];
switch ($project) {
//订单驳回修改
case 'self_order_edit':
$template = config('project.self_order_edit');
$rs = $app->template_message->send([
'touser' => $openid,
'template_id' => $template['template_id'],
'url' => $template['url'],
'data' => [
'first' => '您好,您的订单已被驳回!',
'keyword1' => '订单不符合下单要求,请修改',
'keyword2' => '《中保汽服》',
'keyword3' => $keyword3,
'keyword4' => date('Y-m-d H:i:s', time()),
'remark' => '感谢您的使用!',
],
]);
break;
//订单驳回退款
case 'self_order_refund':
$template = config('project.self_order_refund');
$rs = $app->template_message->send([
'touser' => $openid,
'template_id' => $template['template_id'],
'url' => $template['url'],
'data' => [
'first' => '您好,您的订单已被驳回!',
'keyword1' => '订单不符合下单要求,请申请退款',
'keyword2' => '《中保汽服》',
'keyword3' => $keyword3,
'keyword4' => date('Y-m-d H:i:s', time()),
'remark' => '感谢您的使用!',
],
]);
break;
//退款审核不通过
case 'self_order_fail':
$template = config('project.self_order_fail');
$rs = $app->template_message->send([
'touser' => $openid,
'template_id' => $template['template_id'],
'url' => $template['url'],
'data' => [
'first' => '您好,您的申请退款已被驳回!',
'keyword1' => '请重新申请退款',
'keyword2' => '《中保汽服》',
'keyword3' => $keyword3,
'keyword4' => date('Y-m-d H:i:s', time()),
'remark' => '感谢您的使用!',
],
]);
break;
//代客户-订单驳回修改
case 'replace_order_edit':
$template = config('project.replace_order_edit');
$rs = $app->template_message->send([
'touser' => $openid,
'template_id' => $template['template_id'],
'url' => $template['url'],
'data' => [
'first' => '您好,您的代下订单已被驳回!',
'keyword1' => '请修改后重新提交',
'keyword2' => '《中保汽服》',
'keyword3' => $keyword3,
'keyword4' => date('Y-m-d H:i:s', time()),
'remark' => '感谢您的使用!',
],
]);
break;
}
if (empty($rs) || $rs['errcode'] != 0) {
return ['', 5001, $rs['errmsg']];
}
return ['', 1, $rs['errmsg']];
}
/**
* 发送二次
*/
public static function sendListMessage($project, $user_openid, $pay_openid, $keyword3)
{
$config = config('wechat.official_account');
$app = Factory::officialAccount($config);
$user = [];
$pay = [];
switch ($project) {
//代客户-订单驳回退款 推广员
case 'replace_order_refund':
$template = config('project.replace_order_refund');
$user = $app->template_message->send([
'touser' => $user_openid,
'template_id' => $template['template_id'],
'url' => $template['url'],
'data' => [
'first' => '您好,您的订单已被驳回!',
'keyword1' => '订单不符合下单要求,请申请退款',
'keyword2' => '《中保汽服》',
'keyword3' => $keyword3,
'keyword4' => date('Y-m-d H:i:s', time()),
'remark' => '感谢您的使用!',
],
]);
//代客户-订单驳回退款 用户
$pay = $app->template_message->send([
'touser' => $pay_openid,
'template_id' => $template['template_id'],
'url' => $template['url'],
'data' => [
'first' => '您好,您的订单已被驳回!',
'keyword1' => '订单不符合下单要求,请申请退款',
'keyword2' => '《中保汽服》',
'keyword3' => $keyword3,
'keyword4' => date('Y-m-d H:i:s', time()),
'remark' => '感谢您的使用!',
],
]);
break;
//代客户-退款审核不通过
case 'replace_order_fail':
$template = config('project.replace_order_fail');
$user = $app->template_message->send([
'touser' => $user_openid,
'template_id' => $template['template_id'],
'url' => $template['url'],
'data' => [
'first' => '您好,您的申请退款订单已被驳回!',
'keyword1' => '您的申请退款不通过',
'keyword2' => '《中保汽服》',
'keyword3' => $keyword3,
'keyword4' => date('Y-m-d H:i:s', time()),
'remark' => '感谢您的使用!',
],
]);
//代客户-订单驳回退款 用户
$pay = $app->template_message->send([
'touser' => $pay_openid,
'template_id' => $template['template_id'],
'url' => $template['url'],
'data' => [
'first' => '您好,您的申请退款订单已被驳回!',
'keyword1' => '您的申请退款不通过',
'keyword2' => '《中保汽服》',
'keyword3' => $keyword3,
'keyword4' => date('Y-m-d H:i:s', time()),
'remark' => '感谢您的使用!',
],
]);
break;
}
if (empty($user) || $user['errcode'] != 0) {
return ['', 5001, $user['errmsg']];
}
if (empty($pay) || $pay['errcode'] != 0) {
return ['', 5001, $pay['errmsg']];
}
return ['', 1, $user['errmsg']];
}
}