正在显示
1 个修改的文件
包含
73 行增加
和
2 行删除
@@ -11,6 +11,7 @@ use think\addons\Controller; | @@ -11,6 +11,7 @@ use think\addons\Controller; | ||
11 | use think\Db; | 11 | use think\Db; |
12 | use think\Response; | 12 | use think\Response; |
13 | use think\Session; | 13 | use think\Session; |
14 | +use app\api\controller\Index; | ||
14 | use Yansongda\Pay\Exceptions\GatewayException; | 15 | use Yansongda\Pay\Exceptions\GatewayException; |
15 | use Yansongda\Pay\Pay; | 16 | use Yansongda\Pay\Pay; |
16 | 17 | ||
@@ -280,8 +281,7 @@ class Api extends Controller | @@ -280,8 +281,7 @@ class Api extends Controller | ||
280 | $orderlog['createtime'] = time(); | 281 | $orderlog['createtime'] = time(); |
281 | Db::name('order_log')->insert($orderlog); | 282 | Db::name('order_log')->insert($orderlog); |
282 | $this->SendMessage($cks['id']); | 283 | $this->SendMessage($cks['id']); |
283 | - $index=new \app\api\controller\Index(); | ||
284 | - $index->senWxmsgToDriverUser($cks['id']); | 284 | + $this->senWxmsgToDriverUser($cks['id']); |
285 | } | 285 | } |
286 | } | 286 | } |
287 | 287 | ||
@@ -289,4 +289,75 @@ class Api extends Controller | @@ -289,4 +289,75 @@ class Api extends Controller | ||
289 | //下面这句必须要执行,且在此之前不能有任何输出 | 289 | //下面这句必须要执行,且在此之前不能有任何输出 |
290 | return $pay->success()->send(); | 290 | return $pay->success()->send(); |
291 | } | 291 | } |
292 | + | ||
293 | + function senWxmsgToDriverUser($order_id) | ||
294 | + { | ||
295 | + $order=Db::name("order")->find($order_id); | ||
296 | + if($order['driver_id']){ | ||
297 | + $driver=Db::name("driver")->find($order['driver_id']); | ||
298 | + $user=Db::name("user")->find($driver['user_id']); | ||
299 | + $wct_user=Db::name("wct_user")->where("unionid",$user['unionid'])->find(); | ||
300 | + $wxopenid=$wct_user['wx_openid']; | ||
301 | + $sendInfo = array( | ||
302 | + 'first' => array('value' => "汽车票出票状态通知", 'color' => "#743A3A"), | ||
303 | + 'thing2' => array('value' => "{$order['starting_point']}-{$order['end_point']}", 'color' => '#173177'), | ||
304 | + 'time3' => array('value' =>urlencode(date('Y-m-d H:i:s', $order['reservation_time'])), 'color' => '#173177'), | ||
305 | + 'thing7' => array('value' =>"{$order['position']}", 'color' => '#173177'), | ||
306 | + 'phone_number5' => array('value' => "{$order['phone']}", 'color' => '#173177'), | ||
307 | + ); | ||
308 | + | ||
309 | + | ||
310 | + if ($wxopenid) { | ||
311 | + $config = get_addon_config('wechat'); | ||
312 | + $tourl = ''; | ||
313 | + $ywt_appid = 'wxb7dd0c03865a94e0'; | ||
314 | + $pagepath = ''; | ||
315 | + $res = $this->sendAstuWxMsgToAgent($sendInfo, $wxopenid, $tourl, $config['app_id'], $config['secret'], $ywt_appid, $pagepath); | ||
316 | + | ||
317 | + print_r($res);return; | ||
318 | + //file_put_contents("pcl_wct_send.log", date("Y-m-d H:i:s") . "1-2-" . json_encode($res, JSON_UNESCAPED_UNICODE) . PHP_EOL, FILE_APPEND); | ||
319 | + } | ||
320 | + } | ||
321 | + } | ||
322 | + /** | ||
323 | + * 微信公众号 | ||
324 | + * 用户下订单 消息推送 | ||
325 | + */ | ||
326 | + function sendAstuWxMsgToAgent($info, $openid, $tourl, $appid, $secret, $ywt_appid, $pagepath) | ||
327 | + { | ||
328 | + $myurl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret; | ||
329 | + $json_token = $this->http_request($myurl); | ||
330 | + $access_tokens = json_decode($json_token, true); | ||
331 | + $access_token = $access_tokens['access_token']; | ||
332 | + $template = array( | ||
333 | + 'touser' => $openid, // | ||
334 | + 'template_id' => 'zQaLnhEOQxdGOKJlDUAfEoNY4NTmNWy9a9vYzkZjGn8', //模板消息id 必须修改 | ||
335 | + 'url' => $tourl, //点击链接 | ||
336 | + "miniprogram" => [], | ||
337 | + 'topcolor' => "#173177", | ||
338 | + 'data' => $info | ||
339 | + ); | ||
340 | + | ||
341 | + $json_template = json_encode($template); | ||
342 | + $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $access_token; | ||
343 | + $json = $this->http_request($url, urldecode($json_template)); | ||
344 | + $rs = json_decode($json, true); | ||
345 | + return $rs; | ||
346 | + } | ||
347 | + function http_request($url, $data = array()) | ||
348 | + { | ||
349 | + $ch = curl_init(); | ||
350 | + curl_setopt($ch, CURLOPT_URL, $url); | ||
351 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | ||
352 | + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); | ||
353 | + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); | ||
354 | + // 我们在POST数据哦! | ||
355 | + curl_setopt($ch, CURLOPT_POST, 1); | ||
356 | + // 把post的变量加上 | ||
357 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $data); | ||
358 | + $output = curl_exec($ch); | ||
359 | + curl_close($ch); | ||
360 | + return $output; | ||
361 | + } | ||
362 | + | ||
292 | } | 363 | } |
-
请 注册 或 登录 后发表评论