public function deskAction()
 {
     $mem = new Member();
     $mem->auth();
     $member = C('MEMBER');
     $plid = intval(I('get.p'));
     if (empty($plid)) {
         $this->error('请求错误');
     }
     $m = new Pay();
     $log = $m->fetchLog($plid);
     if ($log == Pay::STATUS_DISBURSED || $log['uid'] != $member['uid']) {
         $this->error('错误的支付订单');
     }
     Pay::loadSettings();
     $setting = C('PAY');
     $pay = array();
     $pay['weixin'] = $setting[Pay::OPT_WEIXIN];
     if ($pay['weixin']['enable']) {
         $wParams = $m->payWeixin($log);
         $this->assign('wParams', $wParams);
     }
     $pay['alipay'] = $setting[Pay::OPT_ALIPAY];
     if ($pay['alipay']['enable']) {
         $aParams = $m->payAlipay($log);
         $this->assign('aParams', $aParams);
     }
     $this->assign('pay', $pay);
     $this->assign('trade', $log);
     $this->display('desk');
 }
Example #2
0
 public function _credits($attr, $content)
 {
     Member::loadSettings();
     $setting = C('MS');
     $credits = $setting[Member::OPT_CREDITS];
     $ds = array();
     if (!in_array($attr['scope'], array('enabled', 'disabled', 'all'))) {
         $attr['scope'] = 'enabled';
     }
     foreach ($credits as $row) {
         if (!empty($row['enabled'])) {
             if ($attr['scope'] == 'enabled' || $attr['scope'] == 'all') {
                 $ds[] = $row;
                 continue;
             }
         } else {
             if ($attr['scope'] == 'disabled' || $attr['scope'] == 'all') {
                 $ds[] = $row;
                 continue;
             }
         }
     }
     $s = '<select name="' . $attr['name'] . '" class="form-control"><option value="">请选择积分类型</option>';
     foreach ($ds as $row) {
         $selected = '<?php echo ' . $attr['value'] . ' == "' . $row['name'] . '" ? " selected" : "" ?>';
         $s .= "<option value=\"{$row['name']}\"{$selected}>{$row['title']}</option>";
     }
     $s .= '</select>';
     return $s;
 }
 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('访问错误');
 }
Example #4
0
 /**
  * @param $log
  * @return js payment object
  */
 public function payWeixin($log)
 {
     self::loadSettings();
     $setting = C('PAY');
     $pay = $setting[self::OPT_WEIXIN];
     $a = new Account();
     $account = $a->getAccount($pay['account']);
     $pay['appid'] = $account['appid'];
     $pay['secret'] = $account['secret'];
     $wOpt = array();
     $m = new Member();
     $fan = $m->fetchFan($log['uid'], $pay['account']);
     $package = array();
     $package['appid'] = $pay['appid'];
     $package['mch_id'] = $pay['mchid'];
     $package['nonce_str'] = util_random(8);
     $package['body'] = $log['title'];
     $package['attach'] = $log['plid'];
     $package['out_trade_no'] = md5($log['plid']);
     $package['total_fee'] = $log['fee'] * 100;
     $package['spbill_create_ip'] = get_client_ip();
     $package['time_start'] = date('YmdHis', TIMESTAMP);
     $package['time_expire'] = date('YmdHis', TIMESTAMP + 600);
     $package['notify_url'] = __HOST__ . U('wander/payment/weixin/t/notify');
     $package['trade_type'] = 'JSAPI';
     $package['openid'] = $fan['openid'];
     ksort($package, SORT_STRING);
     $string1 = '';
     foreach ($package as $key => $v) {
         $string1 .= "{$key}={$v}&";
     }
     $string1 .= "key={$pay['key']}";
     $package['sign'] = strtoupper(md5($string1));
     $dat = util_2xml($package);
     $response = Net::httpPost('https://api.mch.weixin.qq.com/pay/unifiedorder', $dat);
     if (is_error($response)) {
         return $response;
     }
     $xml = '<?xml version="1.0" encoding="utf-8"?>' . $response;
     $dom = new \DOMDocument();
     if (!$dom->loadXML($xml)) {
         return error(-1, 'error response');
     }
     $xpath = new \DOMXPath($dom);
     if ($xpath->evaluate("string(//xml/return_code)") == 'FAIL') {
         return error(-2, $xpath->evaluate("string(//xml/return_msg)"));
     }
     if ($xpath->evaluate("string(//xml/result_code)") == 'FAIL') {
         return error(-3, $xpath->evaluate("string(//xml/err_code_des)"));
     }
     $prepayid = $xpath->evaluate("string(//xml/prepay_id)");
     $wOpt['appId'] = $pay['appid'];
     $wOpt['timeStamp'] = TIMESTAMP;
     $wOpt['nonceStr'] = util_random(8);
     $wOpt['package'] = 'prepay_id=' . $prepayid;
     $wOpt['signType'] = 'MD5';
     ksort($wOpt, SORT_STRING);
     $string = '';
     foreach ($wOpt as $key => $v) {
         $string .= "{$key}={$v}&";
     }
     $string .= "key={$pay['key']}";
     $wOpt['paySign'] = strtoupper(md5($string));
     return $wOpt;
 }
Example #5
0
 /**
  * 获取当前会员身份
  */
 public function auth()
 {
     $uid = session('__:uid');
     if (!empty($uid)) {
         $profile = $this->profile($uid);
         if (!empty($profile)) {
             C('MEMBER', $profile);
             return true;
         }
     }
     if (IN_CONTAINER_WEIXIN) {
         Member::loadSettings();
         $setting = C('MS');
         $auth = $setting[Member::OPT_AUTH_WEIXIN];
         if ($auth == '0') {
             $account = null;
         } else {
             $a = new Account();
             $account = $a->getAccount($auth, Account::ACCOUNT_WEIXIN);
             $callback = urlencode(__HOST__ . U('/auth/weixin'));
         }
         if (empty($account)) {
             $account = array();
             $account['appid'] = 'wx2f9d7b7b086d0fd8';
             $callback = urlencode('http://cloud.microb.cn/proxy/auth/weixin?site=' . C(''));
         }
         $state = $_SERVER['REQUEST_URI'];
         $stateKey = substr(md5($state), 0, 8);
         session('auth:forward', array($stateKey, $state));
         $forward = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$account['appid']}&redirect_uri={$callback}&response_type=code&scope=snsapi_base&state={$stateKey}#wechat_redirect";
         redirect($forward);
     } elseif (IN_CONTAINER_ALIPAY) {
     } else {
         $state = $_SERVER['REQUEST_URI'];
         $stateKey = substr(md5($state), 0, 8);
         session('auth:forward', array($stateKey, $state));
         $url = U('/auth/basic?forward=' . $stateKey);
         redirect($url);
     }
     return false;
 }
 public function passportAction()
 {
     $a = new Account();
     $accounts = array();
     $weixins = $a->table('__PLATFORM_WEIXIN__')->field('id')->where("`level`=2")->select();
     if (!empty($weixins)) {
         $ids = coll_neaten($weixins, 'id');
         if (IS_POST) {
             $select = I('post.select');
             if ($select == '0' || in_array($select, $ids)) {
                 Member::loadSettings();
                 $setting = C('MS');
                 $setting[Member::OPT_AUTH_WEIXIN] = $select;
                 Member::saveSettings($setting);
                 $this->success('处理成功');
                 exit;
             }
         }
         $accounts = $a->table('__PLATFORMS__')->where('`id` IN (' . implode(',', $ids) . ')')->select();
     }
     Member::loadSettings();
     $setting = C('MS');
     $auth = $setting[Member::OPT_AUTH_WEIXIN];
     $this->assign('auth', $auth);
     $this->assign('accounts', $accounts);
     C('FRAME_CURRENT', U('control/member/passport'));
     $this->display();
 }