chengkun
2025-05-26 8f3df543230cd4403368b39b9bbe5726d11a0284
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
<?php
 
 
class index_controller extends common
{
 
    function index_action()
    {
 
        $M  =   $this->MODEL('weixin');
 
        if ($_GET["echostr"]) {
 
            $M->valid($_GET['echostr'], $_GET['signature'], $_GET['timestamp'], $_GET['nonce']);
        } else {
 
            $postStr    =   file_get_contents("php://input");
 
            if (!empty($postStr)) {
 
                libxml_disable_entity_loader(true);
 
                $postObj        =   simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
                $fromUsername   =   $this->gpc2sql($postObj->FromUserName);
                $toUsername     =   $this->gpc2sql($postObj->ToUserName);
                $keyword        =   trim($this->gpc2sql($postObj->Content));
                $times          =   time();
                $MsgType        =   $postObj->MsgType;
 
                $topTpl         =   "<xml>
                   <ToUserName><![CDATA[%s]]></ToUserName>
                   <FromUserName><![CDATA[%s]]></FromUserName>
                   <CreateTime>%s</CreateTime>
                   <MsgType><![CDATA[%s]]></MsgType>
                   ";
 
                $bottomStr      =   "<FuncFlag>0</FuncFlag></xml>";
 
                //默认定义
                $this->MsgType  =   'text';
                $centerStr      =   "<Content><![CDATA[未找到相关数据]]></Content>";
 
                if ($MsgType == 'event') {
 
                    $MsgEvent   =   $postObj->Event;
 
                    if ($MsgEvent == 'subscribe') {
 
                        //判断是否为带参数扫码登录
                        if (!empty($postObj->EventKey)) {
 
                            //取出场景值
                            $wxloginid  =   str_replace('qrscene_', '', $postObj->EventKey);
 
                            //判断场景来源
                            if (strpos($wxloginid, 'weixin_') !== false) {
 
                                //场景码回复图文消息
                                $Return         =   $M->sendPubLink($wxloginid);
                                $centerStr      =   $Return['centerStr'];
                                $this->MsgType  =   $Return['MsgType'];
 
                                //调用客服消息发送关注欢迎语
                                $M->sendCustom($fromUsername, 'text');
 
                                //调用客服消息发送增量欢迎方式 图片/小程序
                                if ($this->config['wx_welcom_type'] == 'wxcompic') {
 
                                    $M->sendCustom($fromUsername, 'image');
                                } elseif ($this->config['wx_welcom_type'] == 'wxcomxcx') {
 
                                    $M->sendCustom($fromUsername, 'miniprogrampage');
                                }
                            } elseif (strpos($wxloginid, 'xcx_') !== false) {
 
                                //获取场景码对应小程序卡片数据
                                $xcxInfo    =   $M->getXcxPubLink($wxloginid);
 
                                //调用客服消息发送欢迎语
                                $M->sendCustom($fromUsername);
 
                                //如果有增量欢迎方式 只发送图片 小程序不发送与下方重复
                                if ($this->config['wx_welcom_type'] == 'wxcompic') {
 
                                    $M->sendCustom($fromUsername, 'image', array());
                                }
 
                                //调用客服消息发送场景码对应小程序卡片
                                $M->sendCustom($fromUsername, 'miniprogrampage', $xcxInfo);
 
                                //返回success
                                echo "success";
                                exit();
                            } else {
 
                                $loginType  =   $M->isWxlogin($fromUsername, $wxloginid);
 
                                if (is_array($loginType)) {
 
                                    $result = $loginType['result'];
                                    $utype = $loginType['type'];
                                } else {
 
                                    $result = $loginType;
                                }
                                if (!$result) {
                                    if (isset($utype) && $utype == 'amminwxbind') {
 
                                        $centerStr = "<Content><![CDATA[要绑定的管理员账号不存在!]]></Content>";
                                    } else {
                                        if (isset($utype) && $utype == 'regbindacount') {
 
                                            $centerStr = "<Content><![CDATA[扫码成功,请绑定已有账号或直接创建新账号!]]></Content>";
                                        } else if ($utype == 'regphone') {
 
                                            $centerStr = "<Content><![CDATA[扫码成功,基于安全需要,请绑定手机号,绑定后可以使用该手机号快速登录]]></Content>";
                                        } else {
 
                                            $centerStr = "<Content><![CDATA[扫码关注成功!]]></Content>";
                                        }
                                    }
                                } else {
                                    if (isset($utype) && $utype == 'amminwxbind' || $utype == 'userwxbind') {
 
                                        $centerStr = "<Content><![CDATA[扫码绑定成功!]]></Content>";
                                    } else {
 
                                        $centerStr = "<Content><![CDATA[扫码登录成功!]]></Content>";
                                    }
                                }
                                $this->MsgType = 'text';
                            }
 
                        } else {
 
                            if (!$this->config['wx_welcom_type'] || $this->config['wx_welcom_type'] == 'nowxcom') {
 
                                if ($this->config['wx_welcom']) {
 
                                    $centerStr = "<Content><![CDATA[" . $this->config['wx_welcom']."]]></Content>";
                                } else {
 
                                    $centerStr = "<Content><![CDATA[欢迎您关注" . $this->config['sy_webname'] . "!\n 1:您可以直接回复关键字如【销售】、【销售 XX公司】查找您想要的职位\n绑定您的账户体验更多精彩功能\n感谢您的关注!"."]]></Content>";
                                }
                                //发送红包
                                $wxRedPackM = $this->MODEL('wxredpack');
                                $wxRedPackM->sendRedPack(array('type' => '1', 'openid' => $fromUsername));
                                $this->MsgType = 'text';
                            } else {
 
                                //调用客服消息发送关注欢迎语
                                $M->sendCustom($fromUsername, 'text');
 
                                //调用客服消息发送增量欢迎方式 图片/小程序
                                if ($this->config['wx_welcom_type'] == 'wxcompic') {
 
                                    $M->sendCustom($fromUsername, 'image', array());
                                } elseif ($this->config['wx_welcom_type'] == 'wxcomxcx') {
 
                                    $M->sendCustom($fromUsername, 'miniprogrampage');
                                }
 
                                //发送红包
                                $wxRedPackM = $this->MODEL('wxredpack');
                                $wxRedPackM->sendRedPack(array('type' => '1', 'openid' => $fromUsername));
 
                                echo "success";
                                exit();
                            }
                        }
                    } else if ($MsgEvent == 'SCAN'){ //已关注二维码待参数事件
 
                        //判断是否为带参数扫码登录
 
                        $wxloginid  =   $postObj->EventKey;
 
                        //判断场景来源
                        if (strpos($wxloginid, 'weixin_') !== false) {
 
                            //场景码回复图文消息
                            $Return         =   $M->sendPubLink($wxloginid);
                            $centerStr      =   $Return['centerStr'];
                            $this->MsgType  =   $Return['MsgType'];
 
                        } elseif (strpos($wxloginid, 'xcx_') !== false) {
 
                            //获取场景码对应小程序卡片数据
                            $xcxInfo        =   $M->getXcxPubLink($wxloginid);
 
                            //调用客服消息发送场景码对应小程序卡片
                            $M->sendCustom($fromUsername, 'miniprogrampage', $xcxInfo);
 
                            //返回success
                            echo "success";
                            exit();
                        } else {
 
                            //未绑定则提示
                            $loginType      =   $M->isWxlogin($fromUsername, $wxloginid);
                            if (is_array($loginType)) {
 
                                $result     =   $loginType['result'];
                                $utype      =   $loginType['type'];
                            } else {
 
                                $result     =   $loginType;
                            }
                            if (!$result) {
                                if (isset($utype) && $utype == 'amminwxbind') {
 
                                    $centerStr      =   "<Content><![CDATA[要绑定的管理员账号不存在!]]></Content>";
                                } else {
                                    if (isset($utype) && $utype == 'regbindacount') {
 
                                        $centerStr  =   "<Content><![CDATA[扫码成功,请绑定已有账号或直接创建新账号!]]></Content>";
                                    } else if ($utype == 'regphone') {
 
                                        $centerStr  =   "<Content><![CDATA[扫码成功,基于安全需要,请绑定手机号,绑定后可以使用该手机号快速登录!]]></Content>";
                                    } else {
                                        $centerStr  =   "<Content><![CDATA[扫码关注成功!]]></Content>";
                                    }
                                }
                            } else {
                                if (isset($utype) && $utype == 'amminwxbind' || $utype == 'userwxbind') {
 
                                    $centerStr      =   "<Content><![CDATA[扫码绑定成功!]]></Content>";
                                } else {
 
                                    $centerStr      =   "<Content><![CDATA[扫码登录成功!]]></Content>";
                                }
                            }
                            $this->MsgType = 'text';
                        }
                    } else if ($MsgEvent == 'CLICK') {
 
                        $ismatch    =   true;
                        $EventKey   =   $postObj->EventKey;
 
                        if ($EventKey == '我的帐号') {
 
                            $Return =   $M->bindUser($fromUsername);
                        } elseif ($EventKey == '我的消息') {
 
                            $Return =   $M->myMsg($fromUsername);
                        } elseif ($EventKey == '面试邀请') {
 
                            $Return =   $M->Audition($fromUsername);
                        } elseif ($EventKey == '简历浏览') {
 
                            $Return =   $M->lookResume($fromUsername);
                        } elseif ($EventKey == '刷新简历') {
 
                            $Return =   $M->refResume($fromUsername);
                        } elseif ($EventKey == '推荐职位') {
 
                            $Return =   $M->recJob($fromUsername);
                        } elseif ($EventKey == '刷新职位') {
 
                            $Return =   $M->refJob($fromUsername);
                        } elseif ($EventKey == '职位浏览') {
 
                            $Return =   $M->lookJob($fromUsername);
                        } elseif ($EventKey == '简历投递') {
 
                            $Return =   $M->ApplyJob($fromUsername);
                        } elseif ($EventKey == '兼职报名') {
 
                            $Return =   $M->PartApply($fromUsername);
                        } elseif ($EventKey == '职位搜索') {
 
                            if ($this->config['wx_search']) {
 
                                $Return['centerStr']    =   "<Content><![CDATA[" . $this->config['wx_search'] . "]]></Content>";
                            } else {
 
                                $Return['centerStr']    =   "<Content><![CDATA[直接回复城市、职位、公司名称等关键字搜索您需要的职位信息。\n 如:【经理】、【xx公司】]]></Content>";
                            }
 
                            $Return['MsgType']          =   'text';
 
                        } elseif ($EventKey == '周边职位') {
 
                            $Return['centerStr']        =   "<Content><![CDATA[/可怜 亲,把您的位置先发我一下。\n\n方法:点屏幕左下角输入框旁的“+”,选择“位置”,点“发送”。]]></Content>";
                            $Return['MsgType']          =   'text';
                        }else{
                            $ismatch  =  false;
                        }
                        if ($ismatch){
                            // 按照已有程序,匹配到的,回复匹配到的内容
                            $centerStr      =   $Return['centerStr'];
                            $this->MsgType  =   $Return['MsgType'];
                        }else{
                            // 没有匹配到的,按自动回复处理
                            $Returnone      =   $M->searchKeyword($EventKey);
                            $centerStr      =   $Returnone['centerStr'];
                            $this->MsgType  =   $Returnone['MsgType'];
                        }
                    }
                } elseif ($MsgType == 'LOCATION') {
 
                    $latitude   =   $postObj->Location_X;
                    $longitude  =   $postObj->Location_Y;
                    $url        =   "http://api.map.baidu.com/geocoder/v2/?ak=42966293429086ba859198a2a69bedad&callback=renderReverse&location=" . $latitude . "," . $longitude . "&output=json";
                    $mapinfo    =   file_get_contents($url);
                    $mapinfo    =   str_replace(array('renderReverse&&renderReverse(', ')'), '', $mapinfo);
                    $map_info   =   json_decode($mapinfo, true);
 
                    if ($map_info['result']['addressComponent']['district']) {
 
                        $Return         =   $M->searchJob($map_info['result']['addressComponent']['district'], 1);
                        $centerStr      =   $Return['centerStr'];
                        $this->MsgType  =   $Return['MsgType'];
                    } else {
 
                        $Return['centerStr']    =   "<Content><![CDATA[未找到相关数据]]></Content>";
                        $Return['MsgType']      =   'text';
                    }
 
                } else if ($MsgType == 'text') {
 
                    if ($keyword) {
 
                        $Returnone      =   $M->searchKeyword($keyword);
                        $centerStr      =   $Returnone['centerStr'];
                        $this->MsgType  =   $Returnone['MsgType'];
                    }
                    if ($Returnone['centerStr'] == "") {
 
                        $Returntwo      =   $M->searchJob($keyword);
                        $centerStr      =   $Returntwo['centerStr'];
                        $this->MsgType  =   $Returntwo['MsgType'];
                    }
                }
 
                $topStr = sprintf($topTpl, $fromUsername, $toUsername, $times, $this->MsgType);
                echo $topStr . $centerStr . $bottomStr;
            }
        }
    }
 
    function gpc2sql($str)
    {
 
        $arr    =   array("sleep" => "Sleep", " and " => " an d ", " or " => " Or ", "xor" => "xOr", "%20" => " ", "select" => "Select", "update" => "Update", "count" => "Count", "chr" => "Chr", "truncate" => "Truncate", "union" => "Union", "delete" => "Delete", "insert" => "Insert", "\"" => "“", "'" => "“", "--" => "- -", "\(" => "(", "\)" => ")", "00000000" => "OOOOOOOO", "0x" => "Ox", "0b" => "Ob");
        foreach ($arr as $key => $v) {
            $str = preg_replace('/' . $key . '/isU', $v, $str);
        }
        return $str;
    }
 
    /**
     * 处理公众号绑定微信开放平台之前关注公众号绑定微信用户,获取unionid
     */
    function pcwxbdAll_action()
    {
 
        $userInfoM  =   $this->MODEL('userinfo');
        $count      =   $userInfoM->getMemberNum(array('wxid' => array('<>', '')));
 
        $size       =   30;
        //循环次数
        $num        =   ceil($count / $size);
 
        if (!$_GET['num']) {
 
            $i      =   0;
        } else {
 
            $i      =   $_GET['num'];
        }
 
        $rows       =   $userInfoM->getList(array('wxid' => array('<>', ''), 'limit' => array($i * $size, $size), 'orderby' => 'uid,asc'), array('field' => '`uid`,`wxid`,`unionid`'));
 
        $weixinM    =   $this->MODEL('weixin');
 
        foreach ($rows as $v) {
 
            if (empty($v['unionid'])) {
 
                $info   =   $weixinM->getWxUser($v['wxid']);
 
                if (!empty($info['unionid'])) {
 
                    $userInfoM->upInfo(array('uid' => $v['uid']), array('unionid' => $info['unionid']));
                }
            }
        }
 
        if (($i + 1) >= $num) {
 
            echo "完成";
        } else {
 
            $getnum =   $i + 1;
 
            echo "<script>location.href='" . $this->config['sy_weburl'] . "/weixin/index.php?c=pcwxbdAll&num=" . $getnum . "';</script>";
        }
    }
 
    /**
     * 处理微信小程序绑定微信开放平台之前在小程序内绑定微信用户,获取unionid
     */
    function wxappbdAll_action()
    {
 
        $userInfoM  =   $this->MODEL('userinfo');
        $count      =   $userInfoM->getMemberNum(array('wxopenid' => array('<>', '')));
 
        $size       =   30;
        //循环次数
        $num        =   ceil($count / $size);
 
        if (!$_GET['num']) {
            $i      =   0;
        } else {
            $i      =   $_GET['num'];
        }
 
        $rows       =   $userInfoM->getList(array('wxopenid' => array('<>', ''), 'limit' => array($i * $size, $size), 'orderby' => 'uid,asc'), array('field' => '`uid`,`wxopenid`,`unionid`'));
 
        $weixinM    =   $this->MODEL('weixin');
 
        foreach ($rows as $v) {
 
            if (empty($v['unionid'])) {
 
                $info   =   $weixinM->getWxUser($v['wxopenid']);
 
                if (!empty($info['unionid'])) {
 
                    $userInfoM->upInfo(array('uid' => $v['uid']), array('unionid' => $info['unionid']));
                }
            }
        }
 
        if (($i + 1) >= $num) {
 
            echo "完成";
        } else {
 
            $getnum =   $i + 1;
            echo "<script>location.href='" . $this->config['sy_weburl'] . "/weixin/index.php?c=wxappbdAll&num=" . $getnum . "';</script>";
        }
    }
}
 
?>