作者 郭文星

123123

@@ -231,12 +231,12 @@ function sendAstuWxMsgToAgent($info, $openid, $tourl, $appid, $secret, $ywt_appi @@ -231,12 +231,12 @@ function sendAstuWxMsgToAgent($info, $openid, $tourl, $appid, $secret, $ywt_appi
231 } 231 }
232 } 232 }
233 233
234 -if (!function_exists('senWxmsgToAgentUser')) { 234 +if (!function_exists('senWxmsgToDriverUser')) {
235 235
236 /*** 236 /***
237 * 公众号推送审核信息给经纪人 237 * 公众号推送审核信息给经纪人
238 */ 238 */
239 - function senWxmsgToAgentUser($order_id) 239 + function senWxmsgToDriverUser($order_id)
240 { 240 {
241 $order=Db::name("order")->find($order_id); 241 $order=Db::name("order")->find($order_id);
242 if($order['driver_id']){ 242 if($order['driver_id']){
@@ -5,6 +5,7 @@ namespace app\api\controller; @@ -5,6 +5,7 @@ namespace app\api\controller;
5 use app\api\controller\inspection\Task; 5 use app\api\controller\inspection\Task;
6 use app\common\controller\Api; 6 use app\common\controller\Api;
7 use fast\Http; 7 use fast\Http;
  8 +use think\Db;
8 9
9 /** 10 /**
10 * 首页接口 11 * 首页接口
@@ -20,6 +21,7 @@ class Index extends Api @@ -20,6 +21,7 @@ class Index extends Api
20 */ 21 */
21 public function index() 22 public function index()
22 { 23 {
  24 + $res=$this->senWxmsgToDriverUser(284);
23 $this->success('请求成功'); 25 $this->success('请求成功');
24 } 26 }
25 27
@@ -89,4 +91,76 @@ class Index extends Api @@ -89,4 +91,76 @@ class Index extends Api
89 } 91 }
90 } 92 }
91 93
  94 +
  95 + function senWxmsgToDriverUser($order_id)
  96 + {
  97 + $order=Db::name("order")->find($order_id);
  98 +
  99 + if($order['driver_id']){
  100 + $driver=Db::name("driver")->find($order['driver_id']);
  101 + $user=Db::name("user")->find($driver['user_id']);
  102 + $wct_user=Db::name("wct_user")->where("unionid",$user['unionid'])->find();
  103 + $wxopenid=$wct_user['wx_openid'];
  104 + $sendInfo = array(
  105 + 'first' => array('value' => "汽车票出票状态通知", 'color' => "#743A3A"),
  106 + 'thing2' => array('value' => "{$order['starting_point']}-{$order['end_point']}", 'color' => '#173177'),
  107 + 'time3' => array('value' =>urlencode(date('Y-m-d H:i:s', $order['reservation_time'])), 'color' => '#173177'),
  108 + 'thing7' => array('value' =>"{$order['starting_point']}", 'color' => '#173177'),
  109 + 'phone_number5' => array('value' => "{$order['phone']}", 'color' => '#173177'),
  110 + );
  111 +
  112 +
  113 + if ($wxopenid) {
  114 + $config = get_addon_config('wechat');
  115 + $tourl = '';
  116 + $ywt_appid = 'wxb7dd0c03865a94e0';
  117 + $pagepath = '';
  118 + $res = $this->sendAstuWxMsgToAgent($sendInfo, $wxopenid, $tourl, $config['app_id'], $config['secret'], $ywt_appid, $pagepath);
  119 +
  120 + print_r($res);return;
  121 + //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);
  122 + }
  123 + }
  124 + }
  125 + function http_request($url, $data = array())
  126 + {
  127 + $ch = curl_init();
  128 + curl_setopt($ch, CURLOPT_URL, $url);
  129 + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  130 + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  131 + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  132 + // 我们在POST数据哦!
  133 + curl_setopt($ch, CURLOPT_POST, 1);
  134 + // 把post的变量加上
  135 + curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  136 + $output = curl_exec($ch);
  137 + curl_close($ch);
  138 + return $output;
  139 + }
  140 +
  141 + /**
  142 + * 微信公众号
  143 + * 经纪人审核 消息推送
  144 + */
  145 + function sendAstuWxMsgToAgent($info, $openid, $tourl, $appid, $secret, $ywt_appid, $pagepath)
  146 + {
  147 + $myurl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret;
  148 + $json_token = $this->http_request($myurl);
  149 + $access_tokens = json_decode($json_token, true);
  150 + $access_token = $access_tokens['access_token'];
  151 + $template = array(
  152 + 'touser' => $openid, //
  153 + 'template_id' => 'zQaLnhEOQxdGOKJlDUAfEoNY4NTmNWy9a9vYzkZjGn8', //模板消息id 必须修改
  154 + 'url' => $tourl, //点击链接
  155 + "miniprogram" => [],
  156 + 'topcolor' => "#173177",
  157 + 'data' => $info
  158 + );
  159 +
  160 + $json_template = json_encode($template);
  161 + $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $access_token;
  162 + $json = $this->http_request($url, urldecode($json_template));
  163 + $rs = json_decode($json, true);
  164 + return $rs;
  165 + }
92 } 166 }
@@ -455,3 +455,4 @@ if (!function_exists('array_callback')) { @@ -455,3 +455,4 @@ if (!function_exists('array_callback')) {
455 return array('state' => $state, 'msg' => $msg, 'data' => $data); 455 return array('state' => $state, 'msg' => $msg, 'data' => $data);
456 } 456 }
457 } 457 }
  458 +