-
Notifications
You must be signed in to change notification settings - Fork 2
/
wxch_order.php
234 lines (217 loc) · 7.85 KB
/
wxch_order.php
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
<?php
if($user_id > 0)
{
//$access_token = access_token($db);
$weixin_config_rows = $GLOBALS['db']->getRow("select * from ".$GLOBALS['hhs']->table('weixin_config')."");
$appid = $weixin_config_rows['appid'];
$appsecret =$weixin_config_rows['appsecret'];
$timestamp=gmtime();
$class_weixin=new class_weixin($appid,$appsecret);
$signature=$class_weixin->getSignature($timestamp);
$access_token=$class_weixin->getAccessToken();
$url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token='.$access_token;
$query_sql = "SELECT openid FROM " . $hhs->table('users') . " WHERE user_id = '$user_id'";
$ret_w = $db->getRow($query_sql);
$wxid = $ret_w['openid'];
/*
$sql = "SELECT * FROM hhs_wxch_order WHERE order_name = '$wxch_order_name'";
$cfg_order = $db->getRow($sql);
*/
/**/
$cfg_baseurl = $db->getOne("SELECT cfg_value FROM ".$hhs->table("weixin_cfg")." WHERE cfg_name = 'baseurl'");
//$cfg_murl = $db->getOne("SELECT cfg_value FROM hhs_weixin_cfg WHERE cfg_name = 'murl'");
//$cfg_baseurl="http://" . $_SERVER['HTTP_HOST'] . "/";
preg_match("/^(http:\/\/)?([^\/]+)/i", $cfg_baseurl , $matches);
$cfg_baseurl=$matches[0]."/";
if($wxch_order_name=='pay'){
$w_title = '付款成功';//$cfg_order['title'];
$w_url = $cfg_baseurl.'share.php?team_sign='.$team_sign;
$w_description="恭喜您荣升为团长!马上叫小伙伴来参团,组团成功才能享受优惠哦~";
$picurl='';
}
elseif($wxch_order_name=='warn'){
$w_title = '参团人数不足提醒';
$w_url = $cfg_baseurl.'share.php?team_sign='.$team_sign;
$w_description="您参加的 ".$goods_name."还剩10小时,目前人数不足,尚未组团成功!快去叫身边的小伙伴一起来参团吧";
$picurl='';
}elseif($wxch_order_name=='refund'){
$w_title = '退款提醒';
$w_url = $cfg_baseurl.'user.php?act=order_detail&order_id='.$order_id;
$w_description="您的订单已经成功退款,记得常来看看哦";
$picurl='';
}
elseif($wxch_order_name=='send_order_bonus'){
$w_title = '发送优惠券提醒';
$w_url = $cfg_baseurl.'user.php?act=bonus';
$w_description='亲爱的'.$uname.'您好!恭喜您获得了'.$count.'个红包,金额分别为'.$money;
$picurl='';
}
elseif($wxch_order_name=='refund_team_first'){
$w_title = '团长免单活动';
$w_url = $cfg_baseurl.'user.php?act=order_detail&order_id='.$order_id;
$w_description="您参加的团长免单优惠活动团购成功,现已将您的金额退回您的微信钱包,请注意查收";
$picurl='';
}
elseif($wxch_order_name=='refund_team_discount'){
$w_title = '团长优惠活动';
$w_url = $cfg_baseurl.'user.php?act=order_detail&order_id='.$order_id;
$w_description="您参加的团长优惠活动团购成功,现已将您的优惠金额退回您的微信钱包,请注意查收";
$picurl='';
}
elseif($wxch_order_name=='shipping'){
$orders = $db->getRow("SELECT * FROM " . $hhs->table('order_info') . " WHERE `order_id` = '$order_id' ");
$order_goods = $db->getAll("SELECT * FROM " . $hhs->table('order_goods') . " WHERE `order_id` = '$order_id'");
if(!empty($order_goods))
{
foreach($order_goods as $v)
{
if(empty($v['goods_attr']))
{
$shopinfo .= $v['goods_name'].'('.$v['goods_number'].'),';
}
else
{
$shopinfo .= $v['goods_name'].'('.$v['goods_attr'].')'.'('.$v['goods_number'].'),';
}
}
$shopinfo = substr($shopinfo, 0, strlen($shopinfo)-1);
}
if($orders['pay_status'] == 0)
{
$pay_status = '支付状态:未付款';
}
elseif($orders['pay_status'] == 1)
{
$pay_status = '支付状态:付款中';
}
elseif($orders['pay_status'] == 2)
{
$pay_status = '支付状态:已付款';
}
$wxch_address = "\r\n收件地址:".$orders['address'];
$wxch_consignee = "\r\n收件人:".$orders['consignee'];
$w_title = '发货提醒';
if($orders['order_amount'] == '0.00')
{
$orders['order_amount'] = $orders['money_paid'];
}
$w_url = $cfg_baseurl.'user.php?act=order_detail&order_id='.$order_id;
$w_description = '订单号:'.$orders['order_sn']."\r\n".'商品信息:'.$shopinfo."\r\n总金额:".$orders['order_amount']."\r\n".$pay_status.$wxch_consignee.$wxch_address;
$picurl='';
}
$post_msg = '{
"touser":"'.$wxid.'",
"msgtype":"news",
"news":{
"articles": [
{
"title":"'.$w_title.'",
"description":"'.$w_description.'",
"url":"'.$w_url.'",
"picurl":"'.$picurl.'"
}
]
}
}';
$ret_json = curl_grab_page($url, $post_msg);
$ret = json_decode($ret_json);
//var_dump($ret);exit();
if($ret->errmsg != 'ok')
{
$access_token = new_access_token($db);
$url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token='.$access_token;
$ret_json = curl_grab_page($url, $post_msg);
$ret = json_decode($ret_json);
}
}
function new_access_token($db)
{
$time = time();
$ret = $db->getRow("SELECT * FROM `hhs_weixin_config` WHERE `id` = 1");
$appid = $ret['appid'];
$appsecret = $ret['appsecret'];
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$appsecret";
$ret_json = curl_get_contents($url);
$ret = json_decode($ret_json);
setcookie("access_token",$ret->access_token,time()+7000,'/');
return $ret->access_token;
}/*
function access_token($db)
{
$ret = $db->getRow("SELECT * FROM `hhs_weixin_config` WHERE `id` = 1");
$appid = $ret['appid'];
$appsecret = $ret['appsecret'];
$access_token = $ret['access_token'];
$dateline = $ret['dateline'];
$time = time();
if(($time - $dateline) >= 7200)
{
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$appsecret";
$ret_json = curl_get_contents($url);
$ret = json_decode($ret_json);
if($ret->access_token)
{
$db->query("UPDATE `hhs_weixin_config` SET `access_token` = '$ret->access_token',`dateline` = '$time' WHERE `id` =1;");
return $ret->access_token;
}
}
elseif(empty($access_token))
{
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$appsecret";
$ret_json = curl_get_contents($url);
$ret = json_decode($ret_json);
if($ret->access_token)
{
$db->query("UPDATE `hhs_weixin_config` SET `access_token` = '$ret->access_token',`dateline` = '$time' WHERE `id` =1;");
return $ret->access_token;
}
}
else
{
return $access_token;
}
}*/
function curl_get_contents($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$r = curl_exec($ch);
curl_close($ch);
return $r;
}
function curl_grab_page($url,$data,$proxy='',$proxystatus='',$ref_url='')
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if ($proxystatus == 'true')
{
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
}
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
if(!empty($ref_url))
{
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_REFERER, $ref_url);
}
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
ob_start();
return curl_exec ($ch);
ob_end_clean();
curl_close ($ch);
unset($ch);
}
?>