private function procAlipay() { $post = I('post.', '', ''); if ($post['service'] == 'alipay.service.check') { $this->platform->touchCheck(); } if ($post['service'] == 'alipay.mobile.public.message.notify') { $xml = '<?xml version="1.0" encoding="utf-8"?>' . iconv('gbk', 'utf-8', $post['biz_content']); $message = $this->platform->parse($xml); //Log::write(var_export($message, true), Log::INFO); // booking 登记会员 $this->platform->booking($message); $this->route($message); } }
public function booking($message) { $fan = array(); $fan['openid'] = $message['from']; $fan['unionid'] = $message['from']; $fan['subscribe'] = 1; if ($message['type'] == 'subscribe') { $fan['subscribetime'] = $message['time']; } elseif ($message['type'] == 'unsubscribe') { $fan['subscribe'] = 0; $fan['unsubscribetime'] = $message['time']; } else { $fan['subscribetime'] = TIMESTAMP; } $tag = @json_decode($message['original']['userinfo'], true); if (!empty($tag)) { $fan['tag'] = serialize($tag); } parent::booking($fan); }
public function weixinAction() { $code = I('get.code'); if (!empty($code)) { Member::loadSettings(); $setting = C('MS'); $auth = $setting[Member::OPT_AUTH_WEIXIN]; if ($auth == '0') { exit('request error'); } else { $a = new Account(); $account = $a->getAccount($auth, Account::ACCOUNT_WEIXIN); $url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid={$account['appid']}&secret={$account['secret']}&code={$code}&grant_type=authorization_code"; $ret = Net::httpGet($url); if (!is_error($ret)) { $auth = @json_decode($ret, true); if (is_array($auth) && !empty($auth['openid'])) { $condition = '`platformid`=:platform AND `openid`=:openid'; $pars = array(); $pars[':platform'] = $account['id']; $pars[':openid'] = $auth['openid']; $fan = $a->table('__MMB_MAPPING_FANS__')->where($condition)->bind($pars)->find(); if (empty($fan)) { $platform = Platform::create($account['id']); $info = $platform->fansQueryInfo($auth['openid'], true); $fan = array(); $fan['platformid'] = $account['id']; $fan['uid'] = 0; $fan['openid'] = $auth['openid']; if (!is_error($info)) { if (!empty($info['original']['unionid'])) { $fan['unionid'] = $info['original']['unionid']; $uid = $a->table('__MMB_MAPPING_FANS__')->field('uid')->where("`unionid`=`{$info['original']['unionid']}`")->find(); if (!empty($uid)) { $fan['uid'] = $uid; } } $fan['subscribe'] = $info['original']['subscribe']; $fan['subscribetime'] = $info['original']['subscribe_time']; unset($info['original']); $fan['info'] = serialize($info); } $fan['unsubscribetime'] = 0; $a->table('__MMB_MAPPING_FANS__')->data($fan)->add(); } $stateKey = I('get.state'); $state = session('auth:forward'); session('auth:forward', null); if ($state[0] == $stateKey) { $forward = $state[1]; } else { $forward = U('/'); } if (stripos($forward, '?') !== false) { $forward .= '&wxref=mp.weixin.qq.com#wechat_redirect'; } else { $forward .= '?wxref=mp.weixin.qq.com#wechat_redirect'; } if (!empty($fan['uid'])) { //登陆 $m = new Member(); $member = $m->profile($uid); if (!empty($member)) { $m->login($fan['uid']); redirect($forward); } } if ($setting[Member::OPT_POLICY] == Member::OPT_POLICY_CLASSICAL) { //兼容模式, 创建新用户 $this->error('兼容模式暂未支持'); redirect($forward); } else { //统一模式, 注册新用户 session('fan:weixin', $fan); if (!empty($fan['info'])) { $fan['info'] = unserialize($fan['info']); } $this->assign('fan', $fan); $this->assign('forward', $forward); $this->display('weixin'); } return; } else { $this->error('微信授权失败错误信息为: ' . $ret); } } $this->error('微信授权失败错误信息为: ' . $ret['message']); } } exit('访问错误'); }