50000 && $from_qrcode_id < 80000) {//如果是分销用户则网分销用户的数据库添加数据 $userTab->editFxWeChatFxUid($openid, $from_qrcode_id); } return ''; } /** * Des:用户取消关注事件 * Name: unsubscribe * @param $content * @return string * @author 倪宗锋 */ public function unsubscribe($content) { if (empty($content['FromUserName'])) { return ''; } $openid = $content['FromUserName']; $userTab = new WechatUser(); $getUser = $userTab->getUserInfoByOpenId($openid); if (isset($getUser['OPENID']) && $getUser['OPENID'] == $openid) {//已存在则修改为已关注 $this->updateUser($openid); return ''; } $this->addUser($openid);//添加用户 return ''; } /** * Des:扫一扫数处理 * Name: scan * @param $content * @return bool|string * @author 倪宗锋 */ public function scan($content) { if (empty($content['FromUserName'])) { return false; } $from_qrcode_id = 0; if (!empty($content['EventKey'])) { $from_qrcode_id = (int)$content['EventKey']; } $openid = $content['FromUserName']; $userTab = new WechatUser(); if ($from_qrcode_id > 50000 && $from_qrcode_id < 1000000) {//如果是分销用户则网分销用户的数据库添加数据 $userTab->editFxWeChatFxUid($openid, $from_qrcode_id); } return ''; } /** * Des:添加用户到数据库 * Name: addUser * @param $openid * @return string * @author 倪宗锋 */ public function addUser($openid, $from_qrcode_id = 0) { $userTab = new WechatUser(); $contentConfig = Util::getSiteContantsConfig(); $res = $this->getUserInfoFromWx($openid); if (isset($res['subscribe']) && $res['subscribe'] == 1) {//用户是关注状态 $data = array( 'CITY' => $res['city'], 'IS_REGISTER' => 1, 'NICKNAME' => $res['nickname'], 'SEX' => $res['sex'], 'FROM_QRCODE_ID' => $from_qrcode_id, 'COUNTRY' => $res['country'], 'PROVINCE' => $res['province'], 'OPENID' => $openid, 'from_source' => $contentConfig['org_id'] ); } else { $data = array( 'IS_REGISTER' => 2, 'OPENID' => $openid, 'from_source' => $contentConfig['org_id'] ); } $userTab->insert($data); return ''; } /** * Des:特殊字符串做处理 * Name: updateUser * @param $openid * @return string * @author 倪宗锋 */ public function showOrderInfo($word) { if (is_numeric($word)) { if (strlen($word) == 6 || strlen($word) == 7) { $wx_interface = new WxInterfaceModel(); $result = $wx_interface->sendOrderInfo($word); if ($result['flag']) {//有所查订单 if ($result['data']['send_bus_res_id'] > 0) {//是否派车 $bus_no = $result['data']['bus_no']; $driver_name = $result['data']['driver_name']; $driver_mobile = $result['data']['driver_mobile']; $msgSend = "车牌号:{$bus_no} 司机姓名:{$driver_name} 司机手机:{$driver_mobile}"; $msgSend .= "司机到站会主动联系未到的乘客,不会遗漏客人;请不要随意拨打司机电话,否则会影响司机休息和行车安全。"; } else { $msgSend = '您乘坐的车辆暂未派车,请在发车前一个小时回复订单号获取信息'; } } else { $msgSend = ''; // $msgSend = '您乘坐的车辆暂未派车,请在发车前一个小时回复订单号获取信息'; } } else { $msgSend = ''; } } else { $msgSend = ''; } return $msgSend; } /** * Des:修改用户星系 * Name: updateUser * @param $openid * @return string * @author 倪宗锋 */ protected function updateUser($openid, $from_qrcode_id = 0) { $userTab = new WechatUser(); $contentConfig = Util::getSiteContantsConfig(); $res = $this->getUserInfoFromWx($openid); if (isset($res['subscribe']) && $res['subscribe'] == 1) {//用户是关注状态 $data = array( 'CITY' => $res['city'], 'IS_REGISTER' => 1, 'NICKNAME' => $res['nickname'], 'SEX' => $res['sex'], 'FROM_QRCODE_ID' => $from_qrcode_id, 'COUNTRY' => $res['country'], 'PROVINCE' => $res['province'], ); } else { $data = array( 'IS_REGISTER' => 2 ); } $where = " OPENID = '{$openid}' and from_source = " . $contentConfig['org_id']; $userTab->update($data, $where); return ''; } /** * Des:从微信获取用户信息 * Name: getUserInfoFromWx * @param $openid * @return mixed * @author 倪宗锋 */ public function getUserInfoFromWx($openid) { $token = WxInterface::getAccessToken(); $url = 'https://api.weixin.qq.com/cgi-bin/user/info?access_token=' . $token . '&openid=' . $openid . '&lang=zh_CN'; $res = WxInterface::httpRequest($url); $res = json_decode($res, true); return $res; } }