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');
 }
 public function paymentAction()
 {
     $a = new Account();
     $accounts = array();
     $weixins = $a->table('__PLATFORM_WEIXIN__')->field('`id`, `appid`, `secret`')->where("`level`=2")->select();
     if (!empty($weixins)) {
         $weixins = coll_key($weixins, 'id');
         $ids = coll_neaten($weixins, 'id');
         $accounts = $a->table('__PLATFORMS__')->field('`id`,`title`')->where('`id` IN (' . implode(',', $ids) . ')')->select();
         foreach ($accounts as &$acc) {
             $acc['appid'] = $weixins[$acc['id']]['appid'];
             $acc['secret'] = $weixins[$acc['id']]['secret'];
         }
     }
     Pay::loadSettings();
     $setting = C('PAY');
     if (IS_POST) {
         $input = array();
         $input['alipay'] = I('post.alipay');
         $input['alipay']['enable'] = $input['alipay']['enable'] == 'true' ? 1 : 0;
         if (!empty($input['alipay']['enable'])) {
             if (empty($input['alipay']['partner']) || empty($input['alipay']['account']) || empty($input['alipay']['secret'])) {
                 $this->error('支付宝支付资料输入不完整');
             }
         }
         $setting[Pay::OPT_ALIPAY] = $input['alipay'];
         $input['weixin'] = I('post.weixin');
         $input['weixin']['enable'] = $input['weixin']['enable'] == 'true' ? 1 : 0;
         if (!empty($input['weixin']['enable'])) {
             if (empty($input['weixin']['partner']) || empty($input['weixin']['key']) || empty($input['weixin']['mchid'])) {
                 $this->error('微信支付资料输入不完整');
             }
         }
         $setting[Pay::OPT_WEIXIN] = $input['weixin'];
         if (Pay::saveSettings($setting)) {
             $this->success('操作成功');
             exit;
         } else {
             $this->error('操作失败, 请稍后重试');
         }
     }
     $pay = array();
     $pay['weixin'] = $setting[Pay::OPT_WEIXIN];
     $pay['alipay'] = $setting[Pay::OPT_ALIPAY];
     $this->assign('pay', $pay);
     $this->assign('accounts', $accounts);
     $this->display();
 }
Example #3
0
 public function pay($order)
 {
     $order['addon'] = $this->addon['name'];
     $m = new Pay();
     $ret = $m->saveLog($order);
     if (is_error($ret)) {
         return $ret;
     }
     return U('cash/desk', array('p' => $ret)) . '?showwxpaytitle=1';
 }
 public function alipayAction()
 {
     $t = I('get.t');
     $get = I('get.');
     unset($get['t']);
     Pay::loadSettings();
     $setting = C('PAY');
     $pay = $setting[Pay::OPT_ALIPAY];
     $p = new Pay();
     if ($t == 'return') {
         $plid = $get['out_trade_no'];
         if (empty($plid)) {
             $this->error('非法访问');
         }
         $prepares = array();
         foreach ($get as $key => $value) {
             if ($key != 'sign' && $key != 'sign_type') {
                 $prepares[] = "{$key}={$value}";
             }
         }
         sort($prepares);
         $string = implode($prepares, '&');
         $string .= $pay['secret'];
         $sign = md5($string);
         if ($sign == $get['sign'] && $get['result'] == 'success') {
             $log = $p->fetchLog($plid);
             if (!empty($log)) {
                 dump($log);
                 exit;
                 $site = WeUtility::createModuleSite($log['module']);
                 if (!is_error($site)) {
                     $method = 'payResult';
                     if (method_exists($site, $method)) {
                         $ret = array();
                         $ret['weid'] = $log['weid'];
                         $ret['uniacid'] = $log['uniacid'];
                         $ret['result'] = $log['status'] == '1' ? 'success' : 'failed';
                         $ret['type'] = $log['type'];
                         $ret['from'] = 'return';
                         $ret['tid'] = $log['tid'];
                         $ret['user'] = $log['openid'];
                         $ret['fee'] = $log['fee'];
                         exit($site->{$method}($ret));
                     }
                 }
             }
         }
     }
     if ($t == 'notify') {
         $xml = '<?xml version="1.0" encoding="utf-8"?>' . I('post.notify_data');
         $dom = new \DOMDocument();
         if ($dom->loadXML($xml)) {
             $xpath = new \DOMXPath($dom);
             $plid = $xpath->evaluate('string(//notify/out_trade_no)');
             $post = I('post.');
             $string = "service={$post['service']}&v={$post['v']}&sec_id={$post['sec_id']}&notify_data={$post['notify_data']}";
             $string .= $pay['secret'];
             $sign = md5($string);
             if ($sign == $post['sign']) {
                 $log = $p->fetchLog($plid);
                 if (!empty($log) && $log['status'] == Pay::STATUS_CREATED) {
                     $record = array();
                     $record['status'] = Pay::STATUS_DISBURSED;
                     pdo_update('core_paylog', $record, array('plid' => $log['plid']));
                     $site = WeUtility::createModuleSite($log['module']);
                     if (!is_error($site)) {
                         $method = 'payResult';
                         if (method_exists($site, $method)) {
                             $ret = array();
                             $ret['weid'] = $log['weid'];
                             $ret['uniacid'] = $log['uniacid'];
                             $ret['result'] = 'success';
                             $ret['type'] = $log['type'];
                             $ret['from'] = 'notify';
                             $ret['tid'] = $log['tid'];
                             $ret['user'] = $log['openid'];
                             $ret['fee'] = $log['fee'];
                             $site->{$method}($ret);
                             exit('success');
                         }
                     }
                 }
             }
         }
     }
     if ($t == 'merchant') {
     }
 }