1.登录支付支付平台[https://opendocs.alipay.com/open/270/106291] 下载对应的sdk
2.将对应的SDK放在对应的tp5.1框架对应的目录
3.因为是外部加载的类库所以要使用composer加载下需要配置composer的配置文件composer.json
4.加载后初始化composer加载下
5.下载对应支付宝助手软件
6.生成对应的公钥和私钥
7.项目里面代码配置
public function test(){ $config = array ( //应用ID,您的APPID。 'app_id' => "2016091600527108", //商户私钥 'merchant_private_key' => "MIIEoQIBAAKCAQEAh8HP5Bji9cCWgNJUl3ttdUwOtdUS+eIFEJHWzNjbKOhjccbJxCOlMTAPlRIOnenhWhQmTd9+BsNPTt8MUL9DA3KjLnRZBH5HN+Ru/6zGO67ZM30kz6kPkrsbvpj6EtziaJSPjpXJvCrSW1hx9qZWHq8EMS6xPDHXHF5ikcevVlvn3wJK6Ey5vibyRnr1tqbD9bTT5pRPsm3bV+V9UNEkOLVrHvEdS1dgot+tSZ6iJsfDmqJvDbzvrdJMQK3GqjL6xwB5gii+mDNo4+Tb6XjqH3m3RUpz+P12nOVZGkA7SAHz1Uel8PgjzlIwBcIUc54uxQNHrrPWNWEnjTkFAWUe3wIDAQABAoH/SB6uUn7mE6g8TDNwvQjVHXtKVU7cxeNMzYCsnCaYRyMtsUPp7EkDeR4PKSJuoXWeQjxyHOyeBvm7KCtWX488CpjcF9G3eKudKhQw46LlrM82lCPnampl242LL7YVI/A0V1qU6SqqAUy+c8iIwn+bQLG5iGdFwLS5kliSBOAQRc/HJ3ox37GX3/JRoGx9BI1rVXA+I8hr9cjE5wji1ZZ3D5FiKfuOKbzcVJ90Z97WfECGeJjqaKCyNqvSI2SFA1IntIPBcVnbBS5rMClQRTley01cMCHq2mT6uAPYq5gPMIe/Ndl5jWFoNBAv3DFijGv3jlE3gs5vu4TZBSbuf9vBAoGBAMGT/Gy0yQnPV/A2EBf5F1pC0KpaKWWWRAmbQhKkklfPEUJJZ7d7StEQ6j/noL0f8YdjxvUPBty8PznioKmmIHZaNEtA0Vnotx/j2maxkeJr0+67hNukR0oslgJT+orgDgahiWxTlaGSCR8iVZ+XgVhHqDgjcVs/2YdXtghBI8S7AoGBALOIqPnGjDhGQ1l0qqZSMHj4zl8MXpA9qHJTmIVFtNK4o1LAJEdru5M00C82FegfI2RDzZJ0RtFcLVwjS+AEX2Ccel9GyafAW3V7LykciZa56UH350dqtn0qrGSLFyOjFAvO2w2Qew5QGyee8aRnxUd5Dk/eChvTuz1P3W5ZHv4tAoGAW646DEYnPPUtogAI6UG5FK+2YignmQxtFtuolGnLQbk5ZFqdu6GyEohfWXrbfxck7kmMTj4asuqZS1IRY6fhkgww3j9Jp7p3GKxyoNaS0FjfXB8F0nzgormxJlMdwy5QlkVlb5+6q3YdydgaE2bPBL+TZVsr8dqwrNAWz5wCU8cCgYBGVE2lcyLw1I2DmJFVEDNO4GCvmT/eD1lSV+8Snijkt1G7k+tiUxCq7PB03iIcyT3rBCieq5AmaY6XXnhVrEDUrte9RRSv80mgrv3dhAFeGzwGDJ/8ORB93d6kkFwjKLosmf7zxFqAU98fWUNd3QzKH+D8ZoXdOsdJkGS02pKqjQKBgQCeWRZer+m3DoLVMSKbXsv+GMWIehroniNp5X3pzIyctdS+tyQOnPnb9lpvnvD/Qag4ne7JteYhiCQGkFGXuxyyM+1OrbvLf2uy1rO7i9QFAQJghHHX3COlWFhho3n/60odmYyjD3cX64OwzaaE9ioq5J2VSaf1ay96nWgVMdqiwA==", //异步通知地址 'notify_url' => "", //同步跳转 'return_url' => "http://www.edu.com/index/suc", //编码格式 'charset' => "UTF-8", //签名方式 'sign_type'=>"RSA2", //支付宝网关 'gatewayUrl' => "https://openapi.alipaydev.com/gateway.do", //支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。 'alipay_public_key' => "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAu/QlP+m2M3bxSlQ/DOYbrBynmKiGAmpdCBrg2iLOvARvFuhYFJBb7em4MICvL8S1oj1mPIH7xPiBunc+W9Jgmm6j86tDJma4ylPucgTWTpa2Uv6y5ZW/Co2GJrQouq0wtbLV99NagLxLufFdusciXW6NqgxkptHGscW0HZajqIKk1Qv605nLWkrO4pmvlQps3ffxcds7GaUnBUpnBU7anEqkZcpY3w/B4Q8TxirXfSNRswnSLV9Tt70GQWqD01/hRPKL1wWK6uzaJ8MVbeXPUyZFuo+o8f5BHUTfxFww5cTbkelr90jA53cZgkcriGc4G5Efp1QTSjC24oqrIH10EQIDAQAB", ); //商户订单号,商户网站订单系统中唯一订单号,必填 $out_trade_no = 12321; //订单名称,必填 $subject = trim("testdsfs"); //付款金额,必填 $total_amount = 30; //商品描述,可空 $body = trim("sdfds"); //构造参数 $payRequestBuilder = new AlipayTradePagePayContentBuilder(); $payRequestBuilder->setBody($body); $payRequestBuilder->setSubject($subject); $payRequestBuilder->setTotalAmount($total_amount); $payRequestBuilder->setOutTradeNo($out_trade_no); $aop = new AlipayTradeService($config); $response = $aop->pagePay($payRequestBuilder,$config['return_url'],$config['notify_url']); // //输出表单 // var_dump($response); }
8.调用结果
9.上面同步通知成功实际已异步为准代码如下
public function alipay_notify() { if (request()->isPost()) { import('alipay.pagepay.service.AlipayTradeService'); $arr = request()->param(); $alipaySevice = new AlipayTradeService(config('alipay')); $alipaySevice->writeLog(var_export(request()->param(), true)); $result = $alipaySevice->check($arr); if ($result) {//验证成功 //商户订单号 $out_trade_no = $arr['out_trade_no']; //支付宝交易号 $trade_no = $arr['trade_no']; if ($arr['trade_status'] == 'TRADE_FINISHED' || $arr['trade_status'] == 'TRADE_SUCCESS') { //查询订单是否真的已支付 import('alipay.pagepay.buildermodel.AlipayTradeQueryContentBuilder'); $RequestBuilder = new AlipayTradeQueryContentBuilder(); $RequestBuilder->setOutTradeNo($out_trade_no); $response = $alipaySevice->Query($RequestBuilder); if ($response->trade_status == 'TRADE_SUCCESS' || $response->trade_status == 'TRADE_FINISHED') { } } echo "success"; } else { //验证失败 echo "fail"; } } }
注意:其中有一个错误提示[http://www.tshinet.com/index.php/article/index/id/582.html] [https://www.fengyan.cc/1418.html]