示例#1
0
 function callback($ctx)
 {
     $jump = htmlspecialchars(trim($_GET['jump']));
     self::validate_url($jump);
     if (!$this->appid || !$this->secret) {
         _redirect($jump);
     }
     $code = urlencode(htmlspecialchars(trim($_GET['code'])));
     if (!$code) {
         _redirect($jump);
     }
     $wx_url = 'https://api.weixin.qq.com/sns/oauth2/access_token';
     $wx_url = "{$wx_url}?appid={$this->appid}&secret={$this->secret}&code={$code}&grant_type=authorization_code";
     $resp = Http::get($wx_url);
     $ret = @json_decode($resp, true);
     if (is_array($ret) && $ret['openid']) {
         $connect = WxConnect::get_by('wx_openid', $ret['openid']);
         if ($connect) {
             Logger::info("wx_openid[{$ret['openid']}] oauth login, uid: {$connect->user_id}");
             $profile = Profile::get($connect->user_id);
             if ($profile && $profile->status != Profile::STATUS_LOCK) {
                 UC::force_login($profile);
             }
         } else {
             // 兼容 /weixin/bind, 因为它依赖 session 中的 openid, 所以这里设置
             session_start();
             $_SESSION['wx_openid'] = $ret['openid'];
         }
     } else {
         Logger::info("weixin oauth, code: {$code}, resp: {$resp}, " . Http::$error);
     }
     _redirect($jump);
 }
示例#2
0
 static function get_count($where = '')
 {
     if (strlen($where)) {
         $where = " where 1 and {$where}";
     }
     $sql = "select count(*) from " . WxConnect::table() . $where;
     $count = Db::get_num($sql);
     return $count;
 }
示例#3
0
 static function get_no_bind_users($wx_id)
 {
     $self_table = self::$table_name;
     $wx_connect_table = WxConnect::table();
     $sql = "select {$self_table}.wx_openid from {$self_table}";
     $sql .= " left join {$wx_connect_table}";
     $sql .= " on {$self_table}.wx_openid = {$wx_connect_table}.wx_openid";
     $sql .= " where {$self_table}.wx_id = '{$wx_id}'";
     $sql .= " and {$self_table}.status = " . self::STATUS_YES;
     $sql .= " and {$wx_connect_table}.wx_openid is null";
     return Db::find($sql);
 }
示例#4
0
 function edit($ctx)
 {
     $id = intval($_GET['id']);
     $m = WxConnect::get($id);
     if (!$m) {
         _throw("ID: {$id} 不存在!");
     }
     if ($_POST) {
         $up = array('prj_subscribe' => intval($_POST['f']['prj_subscribe']), 'wx_subscribe' => intval($_POST['f']['wx_subscribe']));
         $m->update($up);
     }
     $ctx->m = $m;
 }
示例#5
0
 function success($ctx)
 {
     $ctx->title = '绑定成功';
     $prj_subscribe_status = $_COOKIE['no_subscribe_prj'] ? WxConnect::PRJ_UNSUBSCRIBED : WxConnect::PRJ_SUBSCRIBED;
     setcookie('no_subscribe_prj', '', time() + 3600);
     if (!$ctx->user) {
         _redirect(_action('/'));
     }
     $uid = $ctx->user['id'];
     $wx_openid = $this->openid;
     if ($uid && $wx_openid) {
         WxConnect::bind($uid, $wx_openid);
     }
     setcookie(WxTmpLogin::COOKIE_KEY_AUTO_BIND_WX, '', time() - 1, '/');
     unset($_SESSION['wx_openid']);
 }
示例#6
0
 function index($ctx)
 {
     $jump = htmlspecialchars(trim($_GET['jump']));
     $host = Html::host();
     if (!preg_match("/http(s)?:\\/\\/[^\\/]*{$host}\\//", $jump)) {
         $jump = '';
     }
     // 验证 token
     $token = htmlspecialchars(trim($_GET['token']));
     if (strlen($token) == 32) {
         $sess = WxTmpLogin::get_session($token);
         if ($sess) {
             WxTmpLogin::del_session($token);
         }
     }
     if (!$sess) {
         #if($token && !$_SESSION['wx_openid']){
         #	_throw("链接已经过期, 请重新获取微信消息!", 200);
         #}
         _redirect($jump);
     }
     session_start();
     $_SESSION['wx_openid'] = $sess['openid'];
     $connect = WxConnect::get_by('wx_openid', $sess['openid']);
     if (!$connect) {
         setcookie(WxTmpLogin::COOKIE_KEY_AUTO_BIND_WX, 1, time() + 3600 * 24, '/');
         Logger::info("not connected wx_openid: {$sess['openid']}");
         UC::logout();
     } else {
         $uid = $connect->user_id;
         $profile = Profile::get($uid);
         setcookie('ltz_wx_binded', 1, time() + 3600 * 24 * 365, "/");
         // 已经绑定了,直接删除该cookie
         if (isset($_COOKIE[WxTmpLogin::COOKIE_KEY_AUTO_BIND_WX])) {
             setcookie(WxTmpLogin::COOKIE_KEY_AUTO_BIND_WX, '', time() - 1, '/');
         }
         Logger::info("wx_openid[{$sess['openid']}] login, uid: {$uid}, {$profile->name}");
         UC::force_login($profile);
     }
     _redirect($jump);
 }
示例#7
0
文件: msg.php 项目: zxw5775/yuhunclub
 private function projects_unsubscribe($xml)
 {
     $from = $xml->FromUserName;
     $to = $xml->ToUserName;
     if (!$this->bind_check($xml)) {
         return;
     }
     $uid = $this->user_profile->id;
     $connect = WxConnect::get_by('wx_openid', $from);
     if ($connect->prj_subscribe !== WxConnect::PRJ_UNSUBSCRIBED) {
         try {
             $connect->update(array('prj_subscribe' => WxConnect::PRJ_UNSUBSCRIBED));
             $this->wx_reply->imm_reply_text($to, $from, '您已经成功退订新项目通知,如需再次订阅可点击【我的账户-订阅项目通知】。');
         } catch (Exception $e) {
             $this->wx_reply->imm_reply_text($to, $from, '抱歉,退订出错,请稍后重试。');
         }
     } else {
         $this->wx_reply->imm_reply_text($to, $from, '您已经成功退订新项目通知,如需再次订阅可点击【我的账户-订阅项目通知】。');
     }
 }
示例#8
0
?>
</td>
	</tr>
	<tr>
		<td>关注项目通知</td>
		<td>
			<?php 
echo Html::select('f[prj_subscribe]', WxConnect::prj_sub_table(), $m->prj_subscribe);
?>
		</td>
	</tr>
	<tr>
		<td>是否粉丝</td>
		<td>
			<?php 
echo Html::select('f[wx_subscribe]', WxConnect::wx_sub_table(), $m->wx_subscribe);
?>
		</td>
	</tr>
	<tr>
		<td></td>
		<td>
			<button class="btn btn-primary">保存</button>
			&nbsp; &nbsp;
			<a class="btn btn-default" href="<?php 
echo _list_url();
?>
">返回</a>
		</td>
	</tr>
</tbody>