1.导入阿里下载的demo包到 根目录/ThinkPHP/Extend/Vendor 改名为Alipay
2.进入 根目录/APP/Conf/config.php 加入
'alipay' =>[
'app_id' => "",
//商户私钥
'merchant_private_key' => "",
//编码格式
'charset' => "UTF-8",
//签名方式
'sign_type'=>"RSA2",
//支付宝网关
'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
//支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
'alipay_public_key' => "",
],
3.进入/APP/Common/common.php 加入
function alipay($post,$notify_url,$return_url){
$config = C('alipay');
$arr=[
'app_id'=>$config['app_id'],
'merchant_private_key'=>$config['merchant_private_key'],
'notify_url'=>$notify_url,
'return_url'=>$return_url,
'charset'=>$config['charset'],
'sign_type'=>$config['sign_type'],
'gatewayUrl'=>$config['gatewayUrl'],
'alipay_public_key'=>$config['alipay_public_key']
];
// var_dump($arr);
// exit();
// vendor('alipay.AlipayTradeService');
// vendor('alipay.AlipayTradePagePayContentBuilder');
Vendor('Alipay.wappay.service.AlipayTradeService');
Vendor('Alipay.wappay.buildermodel.AlipayTradeWapPayContentBuilder');
$out_trade_no = trim($post['WIDout_trade_no']);
$subject = trim($post['WIDsubject']);
$total_amount = trim($post['WIDtotal_amount']);
$body = trim($post['WIDbody']);
$payRequestBuilder = new \AlipayTradeWapPayContentBuilder();
$payRequestBuilder->setBody($body);
$payRequestBuilder->setSubject($subject);
$payRequestBuilder->setTotalAmount($total_amount);
$payRequestBuilder->setOutTradeNo($out_trade_no);
$aop = new \AlipayTradeService($arr);
$response = $aop->wappay($payRequestBuilder, $arr['return_url'], $arr['notify_url']);
var_dump($response);
}
4.进入支付提交表单页面
public function recharge_post(){
// 支付宝API调用
$arr=[
'WIDout_trade_no'=>'2221122121212121212',
'WIDsubject'=>'在线支付',
'WIDtotal_amount'=>1,
'WIDbody'=>'商品名'
];
session('order',$order);
alipay($arr, 'http://bendi.hioo.cn/ThinkPHP/Extend/Vendor/alipay/notify_url.php', 'http://mitsein.com/alipay.trade.wap.pay-PHP-UTF-8/return_url.php');
}