$smarty->display('wx_account_pushedit.dwt'); break; case "pusheditprofile": $username = getstr($_POST['username']); $password = getstr($_POST['password']); include_once S_ROOT . './source/class_weixin.php'; $ro = new WX_Remote_Opera(); $token = $ro->test_login($username, $password); if ($token != '') { $beenadd = getcount(tname('open_member_weixin'), array('username' => $username, 'state' => 1)); if ($beenadd > 0) { showmessage('此公众号已被绑定,不能作为推送号'); gourl('wx_account.php?ac=pushedit'); exit; } $ro->init($username, $password); $info = $ro->get_account_info(); $setarr = array('ghid' => $info['ghid'], 'weixin_name' => $info['nickname'], 'username' => getstr($_POST['username']), 'password' => getstr($_POST['password']), 'signature' => $info['signature'], 'country' => $info['country'], 'province' => $info['province'], 'city' => $info['city'], 'verifyInfo' => $info['verifyInfo'], 'bindUserName' => $info['bindUserName'], 'account' => $info['account'], 'fakeid' => $info['fakeid'], 'state' => 1); if ($_SGLOBAL['db']->getone('select id from ' . tname('open_member_pushweixin') . ' where op_uid=' . $_SGLOBAL['uid'])) { updatetable(tname('open_member_pushweixin'), $setarr, array('op_uid' => $_SGLOBAL['uid'])); } else { $setarr['op_uid'] = $_SGLOBAL['uid']; $Setarr['addtime'] = $_SGLOBAL['timestamp']; inserttable(tname('open_member_pushweixin'), $setarr); } updatetable(tname('open_member_user'), array('weixin_state' => 0), array('op_uid' => $_SGLOBAL['uid'])); $ro->getheadimg($info['fakeid']); $ro->getqrcode($info['fakeid']); $ro->quick_set_api($_SC['push_api_token'], $_SC['push_api_url']); } else { showmessage('微信用户名或密码错误,或者此微信已被设置');
protected function send_to_member($msg, $question_id = '', $province = '', $nickname = '', $to_uid = 0, $op_wx = array()) { global $_SGLOBAL, $wx; $return = false; $op_wxid = $wx->weixin['op_wxid']; $op_uid = $wx->weixin['op_uid']; $count = 0; $newmsg = $this->question_tpl($msg, $question_id, $province, $nickname); $query = $_SGLOBAL['db']->query("select * from " . tname('open_member_weixin') . " where id='" . $op_wxid . "'"); $op_wx = $_SGLOBAL['db']->fetch_array($query); $ro = new WX_Remote_Opera(); $ro->init($op_wx['username'], $op_wx['password']); $memberlist = $_SGLOBAL['db']->getall('select * from ' . tname('open_member_user') . ' where weixin_state=1 and op_uid="' . $op_uid . '"'); foreach ($memberlist as $k => $v) { $ro->sendmsg($newmsg, $v['weixin_fakeid']); $count++; } $return = $count; return $return; }
protected function send_reply($msg) { global $_SGLOBAL; $create_time = $this->timestamp; $wxid = $this->fromUsername; list($question_id, $content) = explode('#', $msg, 2); $uid = $_SGLOBAL['db']->getone('select uid from ' . tname('open_member_user') . ' where op_uid=' . $this->op_uid . ' and weixin_state=1 and weixin_wxid="' . $wxid . '"'); if ($uid > 0) { $query = $_SGLOBAL['db']->query("select * from " . tname('open_member_user') . " where op_uid=" . $this->op_uid . " and uid=" . $uid); $member = $_SGLOBAL['db']->fetch_array($query); $member['province'] = $_SGLOBAL['db']->getone("SELECT region_name FROM " . tname('region') . " WHERE region_id = " . $member['province']); $asker_uid = $_SGLOBAL['db']->getone('select uid from ' . tname('weixin_question') . ' where id=' . $question_id); $op_wxid = $_SGLOBAL['db']->getone('select op_wxid from ' . tname('weixin_member') . ' where uid=' . $asker_uid); $query = $_SGLOBAL['db']->query("select * from " . tname('open_member_weixin') . " where id='" . $op_wxid . "' and op_uid='" . $this->op_uid . "'"); if ($op_wx = $_SGLOBAL['db']->fetch_array($query)) { $fakeid = $_SGLOBAL['db']->getone('select fakeid from ' . tname('weixin_member') . ' where uid=' . $asker_uid); if ($fakeid) { $replyed = $_SGLOBAL['db']->getone('select replyed from ' . tname('weixin_question') . ' where id=' . $question_id); if ($replyed == 0) { $reply_id = inserttable(tname('weixin_reply'), array('uid' => $uid, 'question_id' => $question_id, 'content' => $content, 'addtime' => $create_time), 1); updatetable(tname('weixin_question'), array('replyed' => 1), array('id' => $question_id)); $ro = new WX_Remote_Opera(); $token = $ro->init($op_wx['username'], $op_wx['password']); $replymsg = $this->reply_tpl($member, $reply_id, $content); $ro->sendmsg($replymsg, $fakeid, $token); return 1; } else { return 2; } } else { return -3; } } else { return -2; } } else { return -1; } }
protected function save_weixin_member() { global $_SGLOBAL, $wx; $create_time = $wx->message['time']; $wxid = $wx->message['from']; $op_wxid = $wx->weixin['op_wxid']; if ($wxid == '') { return false; } $return = false; $member['uid'] = $_SGLOBAL['db']->getone('select uid from ' . tname('weixin_member') . ' where op_wxid=' . $op_wxid . ' and wxid="' . $wxid . '"'); $ro = new WX_Remote_Opera(); $query = $_SGLOBAL['db']->query("select * from " . tname('open_member_weixin') . " where id=" . $op_wxid); if ($op_wx = $_SGLOBAL['db']->fetch_array($query)) { $token = $ro->init($op_wx['username'], $op_wx['password']); if ($member['uid'] > 0) { $member['province'] = $_SGLOBAL['db']->getone('select province from ' . tname('weixin_member') . ' where uid=' . $member['uid']); $member['nickname'] = $_SGLOBAL['db']->getone('select nickname from ' . tname('weixin_member') . ' where uid=' . $member['uid']); } else { $msglist = $ro->getmsglist(); foreach ($msglist as $k => $v) { if ($v['date_time'] == $create_time) { $contactinfo = $ro->getcontactinfo($v['fakeid']); $member['uid'] = inserttable(tname('weixin_member'), array('op_wxid' => $op_wxid, 'wxid' => $wxid, 'fakeid' => $v['fakeid'], 'nickname' => $contactinfo['nick_name'], 'username' => $contactinfo['user_name'], 'country' => $contactinfo['country'], 'province' => $contactinfo['province'], 'city' => $contactinfo['city'], 'sex' => $contactinfo['gender'], 'create_time' => $create_time), 1); $member['fakeid'] = $v['fakeid']; $member['province'] = $contactinfo['province']; $member['nickname'] = $contactinfo['nick_name']; break; } } } //保存头像 $ro->getheadimg($member['fakeid']); return $member; } else { return false; } }