如果你对该文章中的内容有疑问/不解,可以点击此处链接提问
要注明问题和此文章链接地址 点击此处跳转
参数的获取
引用以下几个文件
alipay_core.function.php
alipay_md5.function.php
alipayconfig.class.php
AlipayNotify.class.php
AlipaySubmit.class.php
证书:cacert.pem
下载链接:支付宝支付
使用方法:
if($pay==1){
require_once("./include/ext/alipayconfig.class.php");
//支付类型
$payment_type = "1";
//必填,不能修改
//服务器异步通知页面路径
$notify_url = "http://www.***.com/index.php/alipaynotify.html";
//需http://格式的完整路径,不能加?id=123这类自定义参数
//页面跳转同步通知页面路径
$return_url = "http://www.***.com/index.php/member/alipayreturn.html";/
//需http://格式的完整路径,不能加?id=123这类自定义参数,不能写成http://localhost/
//商户订单号
$out_trade_no = $order_sn['order_sn'];
//商户网站订单系统中唯一订单号,必填
//订单名称
$subject = $order_sn['order_sn'];
//必填
//付款金额
$total_fee = $order_sn['goods_amount'];
//必填
//订单描述
$body = "下单";
//商品展示地址
$show_url = 'http://www.***.com/index.php/member/myclass.html';
//需以http://开头的完整路径,例如:http://www.商户网址.com/myorder.html
$alipaySubmit = new AlipaySubmit($alipay_config);
//防钓鱼时间戳
$anti_phishing_key = '';
//若要使用请调用类文件submit中的query_timestamp函数
//客户端的IP地址
$exter_invoke_ip = get_client_ip();
//构造要请求的参数数组,无需改动
$parameter = array(
"service" => "create_direct_pay_by_user",
"partner" => trim($alipay_config['partner']),
"seller_email" => trim($alipay_config['seller_email']),
"payment_type" => $payment_type,
"notify_url" => $notify_url,
"return_url" => $return_url,
"out_trade_no" => $out_trade_no,
"subject" => $subject,
"total_fee" => $total_fee,
"body" => $body,
"show_url" => $show_url,
"anti_phishing_key" => $anti_phishing_key,
"exter_invoke_ip" => $exter_invoke_ip,
"_input_charset" => trim(strtolower($alipay_config['input_charset']))
);
//建立请求
$html_text = $alipaySubmit->buildRequestForm($parameter,"get", "confirm");
echo $html_text;
}
同步方法:
//验证支付结果
public function alipayreturn() {
if($_GET['trade_status']=="TRADE_SUCCESS" || $_GET['trade_status']=="TRADE_FINISHED") {//验证成功
$condition['order_sn'] = $_GET['out_trade_no'];
$condition['user_id'] = $_SESSION['user']['uid'];
$order = $this->model->table('member_order')->where($condition)->find();
$this->redirect(__APP__."/member/paysuccess/".$order['order_id'].".html");
}
else {
$this->success("支付失败!",__APP__."/member/myclass.html");
}
}
异步方法
//验证支付结果
public functionalipaynotify() {
//业务逻辑
}
王明昌博客
