|
- <?php
- /**
- * 微信推送时 调用指定方法
- * ============================================================================
- * * 版权所有 运游通 * *
- * 网站地址: http://www.zhizhuchuxing.com
- * ----------------------------------------------------------------------------
- * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
- * 使用;不允许对程序代码以任何形式任何目的的再发布。
- * ============================================================================
- * Author By: 倪宗锋
- * PhpStorm WxDoFunction.php
- * Create By 2017/1/5 11:37 $
- */
-
-
- namespace WxInterface\Service;
-
-
- use Model\Model\WechatUser;
- use Util\Util\Util;
- use WxInterface\Model\WxInterfaceModel;
-
- class WxDoFunction
- {
- /**
- * Des:添加用户
- * Name: addUser
- * @param $content
- * @return bool|string
- * @author 倪宗锋
- */
- public function subscribe($content)
- {
- if (empty($content['FromUserName'])) {
- return false;
- }
-
- $from_qrcode_id = 0;
- if (!empty($content['EventKey'])) {
- $from_qrcode_txt = substr($content['EventKey'], 8);
- $from_qrcode_id = (int)$from_qrcode_txt;
- }
- $openid = $content['FromUserName'];
- $userTab = new WechatUser();
- if ($from_qrcode_id > 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;
- }
- }
|