function member_login_weixin($weixin_openid) { global $_GP, $_CMS; if (!empty($weixin_openid)) { $weixin_wxfans = mysqld_select("SELECT * FROM " . table('weixin_wxfans') . " WHERE weixin_openid=:weixin_openid ", array(':weixin_openid' => $weixin_openid)); if (!empty($weixin_wxfans['weixin_openid'])) { $member = mysqld_select("SELECT * FROM " . table('member') . " where weixin_openid=:weixin_openid or openid=:openid limit 1", array(':openid' => $weixin_wxfans['openid'], ':weixin_openid' => $weixin_openid)); if (!empty($member['openid'])) { $_SESSION[MOBILE_ACCOUNT] = $member; } else { $settings = globaSetting(); if (!empty($settings['weixin_autoreg'])) { $openid = date("YmdH", time()) . rand(100, 999); $hasaccount = true; while ($hasaccount) { $hasmember = mysqld_select("SELECT * FROM " . table('member') . " WHERE openid = :openid ", array(':openid' => $openid)); if (!empty($hasmember['openid'])) { $openid = date("YmdH", time()) . rand(100, 999); } else { $hasaccount = false; } } $shareinfo = $_GP['shareid']; if ($shareinfo != $openid && !empty($shareinfo) && (!empty($_SESSION[MOBILE_WEIXIN_OPENID]) || !empty($_SESSION[MOBILE_ALIPAY_OPENID]))) { $share_member = mysqld_select("SELECT * FROM " . table('member') . " WHERE openid = :openid", array(':openid' => $shareinfo)); if (!empty($share_member['openid'])) { if ($_CMS['addons_bj_tbk']) { bj_tbk_base_shareinfo($openid, $shareinfo); } } } $data = array('realname' => $weixin_wxfans['nickname'], 'mobile' => '', 'pwd' => '', 'createtime' => time(), 'status' => 1, 'weixin_openid' => $weixin_openid, 'istemplate' => 0, 'experience' => 0, 'openid' => $openid); mysqld_insert('member', $data); mysqld_update('weixin_wxfans', array('openid' => $openid), array('weixin_openid' => $weixin_openid)); if ($_CMS['addons_bj_tbk']) { bj_tbk_reg_member($openid); } member_login_weixin($weixin_openid); } } } } }
public function do_process() { global $_GP, $_CMS; $settings = globaSetting(); $configdata = $settings['weixintoken']; $token = $configdata; if (!$this->checkSign($token)) { exit('Access Denied'); } if (strtolower($_SERVER['REQUEST_METHOD']) == 'get') { ob_clean(); ob_start(); exit($_GET['echostr']); } if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') { $postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; $message = $this->requestParse($postStr); if (empty($message)) { exit('Request Failed'); } if ($message['type'] == 'text' || $message['type'] == 'CLICK') { $key = $message['content']; if ($message['type'] == 'CLICK') { $key = $message['eventkey']; } if (!empty($key)) { $reply = mysqld_select('SELECT * FROM ' . table('weixin_rule') . " WHERE keywords = :keywords", array(':keywords' => $key)); } if (empty($reply['id']) && !empty($key) && strpos($key, 'hx') == 0 && strpos($key, 'x') == 1 && !empty(strstr($key, 'hx'))) { if ($_CMS['addons_bj_hx']) { //扩展模块代码 $newkey = str_replace('hx', '', $key); $item = mysqld_select("SELECT * FROM " . table('shop_order') . " WHERE ordersn = :ordersn\t", array(':ordersn' => $newkey)); if (empty($item)) { return $this->respText('抱歉,核销订单不存在或被取消', $message); } if ($item['status'] == 3) { return $this->respText('抱歉,核销订单已核销完成,不能重复核销!', $message); } $from_user = $message['from']; $weixin_wxfans = mysqld_select('SELECT * FROM ' . table('weixin_wxfans') . " WHERE weixin_openid = :weixin_openid", array(':weixin_openid' => $from_user)); $str = $this->verifyorder($weixin_wxfans['openid'], $newkey); return $this->respText($str, $message); } } else { if ($_CMS['addons_bj_tbk']) { //扩展模块代码 if (empty($reply['id']) && !empty($key)) { $from_user = $message['from']; $spread = mysqld_select("SELECT * FROM " . table('bj_tbk_qrcode') . " where weixinkey=:weixinkey limit 1", array(':weixinkey' => $key)); if (!empty($spread['id'])) { $weixin_wxfans = mysqld_select('SELECT * FROM ' . table('weixin_wxfans') . " WHERE weixin_openid = :weixin_openid", array(':weixin_openid' => $from_user)); if (!empty($weixin_wxfans['openid'])) { $bj_tbk_member_relect = mysqld_select('SELECT * FROM ' . table('bj_tbk_member_relect') . " WHERE openid = :openid", array(':openid' => $weixin_wxfans['openid'])); //if(empty($bj_tbk_member_relect['isagent'])) //{ // return $this->respText('您还不是代理无法生成二维码',$message); //} $qrcodecache = mysqld_select("SELECT * FROM " . table('bj_tbk_qrcode_cache') . " where qrcodeid=:qrcodeid and from_user=:from_user limit 1", array(':qrcodeid' => $spread['id'], ':from_user' => $from_user)); if (empty($qrcodecache['id']) || empty($qrcodecache['qr_url']) || empty($qrcodecache['media_id']) || empty($qrcodecache['id']) || !empty($qrcodecache['expiretime']) && $qrcodecache['expiretime'] <= TIMESTAMP) { $media_id = bj_tbk_qrcode($qrcodecache, $spread, $from_user, $weixin_wxfans['openid'], true, 'media_id'); return $this->respImage($media_id, $message); // $this->sendcustomIMG($from_user,$media_id); exit; } else { return $this->respImage($qrcodecache['media_id'], $message); } } else { return $this->respText('您还不是会员无法生成二维码', $message); } } } } } } if ($message['type'] == 'subscribe') { $reply = mysqld_select('SELECT * FROM ' . table('weixin_rule') . " WHERE keywords = :keywords", array(':keywords' => subscribe_key)); if (!empty($message['eventkey']) && strlen($message['eventkey']) > 8) { $eventkey = substr($message['eventkey'], 8); } else { $eventkey = $message['eventkey']; } if (!empty($message['from']) && !empty($eventkey)) { bj_tbk_base_shareinfo('', $eventkey, $message['from'], '', 1); } mysqld_update('weixin_wxfans', array('follow' => 1), array('weixin_openid' => $message['from'])); } if ($message['type'] == 'unsubscribe') { mysqld_update('weixin_wxfans', array('follow' => 0), array('weixin_openid' => $message['from'])); } if (empty($reply['id'])) { $reply = mysqld_select('SELECT * FROM ' . table('weixin_rule') . " WHERE keywords = :keywords", array(':keywords' => default_key)); } if ($reply['ruletype'] == 1) { $reply['content'] = htmlspecialchars_decode($reply['description']); $reply['content'] = str_replace(array('<br>', ' '), array("\n", ' '), $reply['content']); $reply['content'] = strip_tags($reply['content'], '<a>'); return $this->respText($reply['content'], $message); } if ($reply['ruletype'] == 2) { $news = array(); $news = array('title' => $reply['title'], 'description' => $reply['description'], 'picurl' => $reply['thumb'], 'url' => $reply['url']); return $this->respNews($news, $message); } exit(''); } }