value('openid'); if(empty($openid)) return [false,'not invaild openid']; $config = config('wx.msg'); switch ($type){ case '1': case '2': $menu_type = $menu_id.'_'.$type; break; case '3': $menu_type = $menu_id.'_'.$type.'_'.$state; break; default : $menu_type = ''; } if(!isset($config['wx_menu'][$menu_type])) return [false,'not invaild menu_type']; $tmp_data = $config['wx_tmp_id'][$config['wx_menu'][$menu_type]]; $detail = $tmp_data['param']; $tmp_id = $tmp_data['tmp_id']; $data = []; foreach ($detail as $k=>$v){ $data[$v] = $order_data[$k]; } list($status,$msg) = $this->sendTmpMsg($openid,$tmp_id,['detail'=>$data]); if(! $status) return [false, $msg]; return [true,'']; } public function sendTmpMsg($openid,$tempid,$data) { $reload_url = $data['reload_url'] ?? ''; list($status, $token) = $this->getToken(); if (!$status) return [false, $token]; $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $token; $post = '{ "touser":"' . $openid . '", "template_id":"' . $tempid . '", "url":"' . $reload_url . '", "miniprogram":{ "appid":"wxc0bc3dfc58b4e00e", "pagepath":"" }, "data":{ "first": { "value":"1", "color":"#173177" }, %s "remark":{ "value":"1", "color":"#173177" } } }'; $content = ""; foreach ($data['detail'] as $k => $v) { $content .= '"' . $k . '": { "value":"' . $v . '", "color":"#173177" },'; } $post = sprintf($post, $content); $res = $this->curlOpen($url, ['post' => $post]); $res = json_decode($res, true); if (isset($res['errcode']) && $res['errcode'] != 0) return [false, $res['errmsg']]; if (isset($res['errcode']) && $res['errcode'] === 0) return [true, '']; return [false, json_encode($res)]; } }