You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

220 lines
7.1 KiB

  1. <?php
  2. /**
  3. * 微信推送时 调用指定方法
  4. * ============================================================================
  5. * * 版权所有 运游通 * *
  6. * 网站地址: http://www.zhizhuchuxing.com
  7. * ----------------------------------------------------------------------------
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
  9. * 使用;不允许对程序代码以任何形式任何目的的再发布。
  10. * ============================================================================
  11. * Author By: 倪宗锋
  12. * PhpStorm WxDoFunction.php
  13. * Create By 2017/1/5 11:37 $
  14. */
  15. namespace WxInterface\Service;
  16. use Model\Model\WechatUser;
  17. use Util\Util\Util;
  18. use WxInterface\Model\WxInterfaceModel;
  19. class WxDoFunction
  20. {
  21. /**
  22. * Des:添加用户
  23. * Name: addUser
  24. * @param $content
  25. * @return bool|string
  26. * @author 倪宗锋
  27. */
  28. public function subscribe($content)
  29. {
  30. if (empty($content['FromUserName'])) {
  31. return false;
  32. }
  33. $from_qrcode_id = 0;
  34. if (!empty($content['EventKey'])) {
  35. $from_qrcode_txt = substr($content['EventKey'], 8);
  36. $from_qrcode_id = (int)$from_qrcode_txt;
  37. }
  38. $openid = $content['FromUserName'];
  39. $userTab = new WechatUser();
  40. if ($from_qrcode_id > 50000 && $from_qrcode_id < 80000) {//如果是分销用户则网分销用户的数据库添加数据
  41. $userTab->editFxWeChatFxUid($openid, $from_qrcode_id);
  42. }
  43. return '';
  44. }
  45. /**
  46. * Des:用户取消关注事件
  47. * Name: unsubscribe
  48. * @param $content
  49. * @return string
  50. * @author 倪宗锋
  51. */
  52. public function unsubscribe($content)
  53. {
  54. if (empty($content['FromUserName'])) {
  55. return '';
  56. }
  57. $openid = $content['FromUserName'];
  58. $userTab = new WechatUser();
  59. $getUser = $userTab->getUserInfoByOpenId($openid);
  60. if (isset($getUser['OPENID']) && $getUser['OPENID'] == $openid) {//已存在则修改为已关注
  61. $this->updateUser($openid);
  62. return '';
  63. }
  64. $this->addUser($openid);//添加用户
  65. return '';
  66. }
  67. /**
  68. * Des:扫一扫数处理
  69. * Name: scan
  70. * @param $content
  71. * @return bool|string
  72. * @author 倪宗锋
  73. */
  74. public function scan($content)
  75. {
  76. if (empty($content['FromUserName'])) {
  77. return false;
  78. }
  79. $from_qrcode_id = 0;
  80. if (!empty($content['EventKey'])) {
  81. $from_qrcode_id = (int)$content['EventKey'];
  82. }
  83. $openid = $content['FromUserName'];
  84. $userTab = new WechatUser();
  85. if ($from_qrcode_id > 50000 && $from_qrcode_id < 1000000) {//如果是分销用户则网分销用户的数据库添加数据
  86. $userTab->editFxWeChatFxUid($openid, $from_qrcode_id);
  87. }
  88. return '';
  89. }
  90. /**
  91. * Des:添加用户到数据库
  92. * Name: addUser
  93. * @param $openid
  94. * @return string
  95. * @author 倪宗锋
  96. */
  97. public function addUser($openid, $from_qrcode_id = 0)
  98. {
  99. $userTab = new WechatUser();
  100. $contentConfig = Util::getSiteContantsConfig();
  101. $res = $this->getUserInfoFromWx($openid);
  102. if (isset($res['subscribe']) && $res['subscribe'] == 1) {//用户是关注状态
  103. $data = array(
  104. 'CITY' => $res['city'],
  105. 'IS_REGISTER' => 1,
  106. 'NICKNAME' => $res['nickname'],
  107. 'SEX' => $res['sex'],
  108. 'FROM_QRCODE_ID' => $from_qrcode_id,
  109. 'COUNTRY' => $res['country'],
  110. 'PROVINCE' => $res['province'],
  111. 'OPENID' => $openid,
  112. 'from_source' => $contentConfig['org_id']
  113. );
  114. } else {
  115. $data = array(
  116. 'IS_REGISTER' => 2,
  117. 'OPENID' => $openid,
  118. 'from_source' => $contentConfig['org_id']
  119. );
  120. }
  121. $userTab->insert($data);
  122. return '';
  123. }
  124. /**
  125. * Des:特殊字符串做处理
  126. * Name: updateUser
  127. * @param $openid
  128. * @return string
  129. * @author 倪宗锋
  130. */
  131. public function showOrderInfo($word)
  132. {
  133. if (is_numeric($word)) {
  134. if (strlen($word) == 6 || strlen($word) == 7) {
  135. $wx_interface = new WxInterfaceModel();
  136. $result = $wx_interface->sendOrderInfo($word);
  137. if ($result['flag']) {//有所查订单
  138. if ($result['data']['send_bus_res_id'] > 0) {//是否派车
  139. $bus_no = $result['data']['bus_no'];
  140. $driver_name = $result['data']['driver_name'];
  141. $driver_mobile = $result['data']['driver_mobile'];
  142. $msgSend = "车牌号:{$bus_no} 司机姓名:{$driver_name} 司机手机:{$driver_mobile}";
  143. $msgSend .= "司机到站会主动联系未到的乘客,不会遗漏客人;请不要随意拨打司机电话,否则会影响司机休息和行车安全。";
  144. } else {
  145. $msgSend = '您乘坐的车辆暂未派车,请在发车前一个小时回复订单号获取信息';
  146. }
  147. } else {
  148. $msgSend = '';
  149. // $msgSend = '您乘坐的车辆暂未派车,请在发车前一个小时回复订单号获取信息';
  150. }
  151. } else {
  152. $msgSend = '';
  153. }
  154. } else {
  155. $msgSend = '';
  156. }
  157. return $msgSend;
  158. }
  159. /**
  160. * Des:修改用户星系
  161. * Name: updateUser
  162. * @param $openid
  163. * @return string
  164. * @author 倪宗锋
  165. */
  166. protected function updateUser($openid, $from_qrcode_id = 0)
  167. {
  168. $userTab = new WechatUser();
  169. $contentConfig = Util::getSiteContantsConfig();
  170. $res = $this->getUserInfoFromWx($openid);
  171. if (isset($res['subscribe']) && $res['subscribe'] == 1) {//用户是关注状态
  172. $data = array(
  173. 'CITY' => $res['city'],
  174. 'IS_REGISTER' => 1,
  175. 'NICKNAME' => $res['nickname'],
  176. 'SEX' => $res['sex'],
  177. 'FROM_QRCODE_ID' => $from_qrcode_id,
  178. 'COUNTRY' => $res['country'],
  179. 'PROVINCE' => $res['province'],
  180. );
  181. } else {
  182. $data = array(
  183. 'IS_REGISTER' => 2
  184. );
  185. }
  186. $where = " OPENID = '{$openid}' and from_source = " . $contentConfig['org_id'];
  187. $userTab->update($data, $where);
  188. return '';
  189. }
  190. /**
  191. * Des:从微信获取用户信息
  192. * Name: getUserInfoFromWx
  193. * @param $openid
  194. * @return mixed
  195. * @author 倪宗锋
  196. */
  197. public function getUserInfoFromWx($openid)
  198. {
  199. $token = WxInterface::getAccessToken();
  200. $url = 'https://api.weixin.qq.com/cgi-bin/user/info?access_token=' . $token . '&openid=' . $openid . '&lang=zh_CN';
  201. $res = WxInterface::httpRequest($url);
  202. $res = json_decode($res, true);
  203. return $res;
  204. }
  205. }