public function createChargeIOS() { $price = $this->data['money']; if ($price < 1) { return array('status' => 0, 'mesage' => '充值金额不正确'); } $type = intval($this->data['type']); $types = array('alipay', 'weixin'); if (!isset($types[$type])) { return array('status' => 0, 'mesage' => '充值方式不支持'); } $version = intval($this->data['version']) ?: 1; //版本 1-系统版 2-直播版 if ($version == 1) { $chargeConfigs = model('Xdata')->get('admin_Config:charge'); } elseif ($version == 2) { $chargeConfigs = model('Xdata')->get('admin_Config:ZBcharge'); } else { return array('status' => 0, 'mesage' => '参数错误'); } if (!in_array($types[$type], $chargeConfigs['charge_platform'])) { return array('status' => 0, 'mesage' => '充值方式不支持'); } $data['serial_number'] = 'CZ' . date('YmdHis') . rand(0, 9) . rand(0, 9); $data['charge_type'] = $type; $data['charge_value'] = $price; $data['uid'] = $this->mid; $data['ctime'] = time(); $data['status'] = 0; $data['charge_sroce'] = intval($price * abs(intval($chargeConfigs['charge_ratio']))); $data['charge_order'] = ''; $result = D('credit_charge')->add($data); if ($result) { $data['charge_id'] = $result; if ($type == 0) { //支付宝支付 $configs = $parameter = array(); $configs['partner'] = $chargeConfigs['alipay_pid']; $configs['seller_id'] = $chargeConfigs['alipay_pid']; $configs['seller_email'] = $chargeConfigs['alipay_email']; $configs['key'] = $chargeConfigs['alipay_key']; $parameter = array('notify_url' => SITE_URL . '/alipay_notify_api.php', 'out_trade_no' => $data['serial_number'], 'subject' => '积分充值:' . $data['charge_sroce'] . '积分', 'total_fee' => $data['charge_value'], 'body' => '', 'payment_type' => 1, 'service' => 'mobile.securitypay.pay', 'it_b_pay' => '1c'); $url = createAlipayUrl($configs, $parameter, 2); //直接返回支付宝支付url } elseif ($type == 1) { $ip = get_client_ip(); //微信支付需要终端ip $order = array('body' => '积分充值:' . $data['charge_sroce'] . '积分', 'appid' => $chargeConfigs['weixin_pid'], 'device_info' => 'APP', 'mch_id' => $chargeConfigs['weixin_mid'], 'nonce_str' => mt_rand(), 'notify_url' => SITE_URL . '/weixin_notify_api.php', 'out_trade_no' => $data['serial_number'], 'spbill_create_ip' => $ip, 'total_fee' => $data['charge_value'] * 100, 'trade_type' => 'APP'); //预支付订单 $weixinpay = new WeChatPay(); $url['url'] = $weixinpay->getPayParam($order, $chargeConfigs['weixin_pid'], $chargeConfigs['weixin_mid'], $chargeConfigs['weixin_key'], 1); $url['out_trade_no'] = $data['serial_number']; } return array('status' => 1, 'mesage' => '', 'data' => $url); } else { $res = array(); $res['status'] = 0; $res['mesage'] = '充值创建失败'; return $res; } }
protected function alipay(array $data) { $chargeConfigs = model('Xdata')->get('admin_Config:charge'); require_once ADDON_PATH . '/library/alipay/alipay.php'; $configs = $parameter = array(); $configs['partner'] = $chargeConfigs['alipay_pid']; $configs['seller_email'] = $chargeConfigs['alipay_email']; $configs['key'] = $chargeConfigs['alipay_key']; $parameter = array("notify_url" => SITE_URL . '/public/pay/alipay_notify.php', "return_url" => SITE_URL . '/public/pay/alipay_return.php', "out_trade_no" => $data['serial_number'], "subject" => '积分充值:' . $data['charge_sroce'] . '积分', "total_fee" => $data['charge_value'], "body" => '', "show_url" => '', "app" => 'public', "mod" => 'Account', "act" => 'scorecharge'); return createAlipayUrl($configs, $parameter); }