CodeIgniter 3 支付宝接口(wap版) 2016-1-16更新
代码如下:1.支付发起:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* alipy支付接口-wap
* @author CRX349
*
*/
class Alipay_wap extends CI_Controller
{
private $alipay_config;
function __construct(){
parent::__construct();
$this->_init_config();
/*加载模块*/
//判断登录
if (!$this->session->userdata('user_in')){
redirect('login');
exit();
}
}
function index()
{
//$this->load->view('alipay');//装载支付视图页面,post到do_alipay
}
function do_alipay(){
/*
支付信息构造
*/
require_once(APPPATH.'libraries/payment/alipay_wap/alipay_submit.class.php');
//构造要请求的参数数组,无需改动
$parameter = array(
"service" => "alipay.wap.create.direct.pay.by.user",
"partner" => trim($this->alipay_config['partner']),
"seller_id" => trim($this->alipay_config['seller_id']),
"payment_type" => '1',
"notify_url" => site_url('alipay_notify_wap/do_notify'),
"return_url" => site_url('alipay_notify_wap/do_return'),
//"seller_email" => trim($this->alipay_config['seller_emaill']),//支付宝帐户,
"out_trade_no" => $order_sn,//$this->input->post('WIDout_trade_no'),//商户订单号
"subject" => $subject,//$this->input->post('WIDsubject'),//订单名称
//"total_fee" => $this->input->post('WIDtotal_fee'),//必填,付款金额
"total_fee" => $money,//订单金额
"body" => $subject,//$this->input->post('WIDbody'),//必填,订单描述
//"show_url" => $this->input->post('WIDshow_url'),//商品展示地址
"show_url" => 'http://www.xmspace.net/',//商品地址
//"anti_phishing_key" => '',//防钓鱼时间戳
//"exter_invoke_ip" => '',//客户端的IP地址
"it_b_pay" => '',
"extern_token" => '',
"_input_charset" => trim(strtolower($this->alipay_config['input_charset']))
);
//建立请求
$alipaySubmit = new AlipaySubmit($this->alipay_config);
$html_text = $alipaySubmit->buildRequestForm($parameter,"get", "正在为您转入支付宝页面...");
//加一个编码页面,避免跳转页面显示错误
header("Content-type:text/html;charset=utf-8");
echo $html_text;
}
/**
* 初始化支付宝配置,详细参数请根据自己实际接口修改
*/
private function _init_config(){
//支付宝帐户
//*******要配置的地方之一 收款账号*********
$alipay_config['seller_emaill'] = '';
//合作身份者id,以2088开头的16位纯数字
//********要配置的地方之二 合作身份者id******
$alipay_config['partner'] = '';
//收款支付宝账号,一般情况下收款账号就是签约账号
$alipay_config['seller_id'] = $alipay_config['partner'];
//安全检验码,以数字和字母组成的32位字符
//********要配置的地方之三 安全检验码*******
$alipay_config['key'] = '';
//签名方式 不需修改
$alipay_config['sign_type'] = strtoupper('MD5');//strtoupper('RSA');
//字符编码格式 目前支持 gbk 或 utf-8
$alipay_config['input_charset'] = strtolower('utf-8');
//商户的私钥(后缀是.pen)文件相对路径
$alipay_config['private_key_path'] = APPPATH . 'libraries/payment/alipay_wap/key/rsa_private_key.pem';
//支付宝公钥(后缀是.pen)文件相对路径
$alipay_config['ali_public_key_path']= APPPATH . 'libraries/payment/alipay_wap/key/alipay_public_key.pem';
//ca证书路径地址,用于curl中ssl校验
//请保证cacert.pem文件在当前文件夹目录中
$alipay_config['cacert'] = APPPATH.'libraries/payment/alipay_wap/cacert.pem';
//访问模式,根据自己的服务器是否支持ssl访问,若支持请选择https;若不支持请选择http
$alipay_config['transport'] = 'http';
$this->alipay_config = $alipay_config;
}
}
?>
2.支付回调:
编辑中
页:
[1]