## 支付宝商家接入 申请公钥和私钥
商家入口及配置
![](https://img.kancloud.cn/32/71/3271d9ff2554ee590e872c122b0f1a71_785x882.png)
*****
![](https://img.kancloud.cn/3b/55/3b55b747c9d5698bd4e785a3694821cb_1467x934.png)
*****
## 开发者中心入口
[链接](https://developers.alipay.com/dev/workspace/key-manage)
https://developers.alipay.com/dev/workspace/key-manage
*****
![](https://img.kancloud.cn/97/03/970347c80036215b706f730905721b3f_1488x873.png)
*****
![](https://img.kancloud.cn/d6/de/d6de18913be35957dcddd8f62146b76c_1028x864.png)
*****
## 获取公钥等
![](https://img.kancloud.cn/ea/f9/eaf9f0dcfb5a0fd6227da617d61812cc_637x370.png)
*****
![](https://img.kancloud.cn/e9/46/e946b5c6664c4e9cbf23123368eae6db_1319x585.png)
*****
![](https://img.kancloud.cn/af/6f/af6f8bc0a4dff189cc48a51ebfaef532_1897x824.png)
## 下载支付宝php __SDK
分为手机端和网页端
网页端
[https://opendocs.alipay.com/open/270/106291](https://opendocs.alipay.com/open/270/106291)
手机端
[https://opendocs.alipay.com/open/203/105910](https://opendocs.alipay.com/open/203/105910)
![](https://img.kancloud.cn/22/46/22468652c72aabf48863ca731dac401b_1623x604.png)
## SDK位置 extend下面
![](https://img.kancloud.cn/b3/26/b32603b7ebc522ca9005c67b0df9d0c7_820x714.png)
*****
修改部分代码 ----添加命名空间,在控制器里面引用
![](https://img.kancloud.cn/01/08/010821b8ace97829c08ab948156f90b4_1198x688.png)
```
~~~
use AlipayTradePagePay\aop\AopClient;
use AlipayTradePagePay\aop\request\AlipayTradePagePayRequest;
use AlipayTradePagePay\pagepay\servier\AlipayTradeService;
~~~
```
## 配置文件配置参数公钥私钥
![](https://img.kancloud.cn/93/41/9341a8b8221f905192e95b8cc7edd768_1569x795.png)
```
~~~
'alipay' =>[
//应用ID,您的APPID。
'app_id' => "2019081366229303",
//商户私钥,您的原始格式RSA私钥
'merchant_private_key' => "MIIEowIBAAKCAQEAk7y/42QOcMZcOQA1jOrEs2+QU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pLkurVBMUSo1STEgBO36Y7nH6B/c814UtsTOK7l9eA+FqdR8FfNMhCSTf7cGe7VwBgXD0fzTQwoiOlr8B2C7zCNClGGjtULLngwB2V1skswXdcL4FQtAqe7PD+UznlhFPYiGt39WWB4QKBgEA4qjGQ6WXqcg7oRPy6IfRG+EnVTnKyG0bbtlji6+XSRGujrzim2WTnRqgKVe7RkGlhGv1bP5tBDWdJBS2TESzQgyLmUmTyPYzEoW7UI/LR8X+EWBOVOkF1Dt/W7aVU5OOpFdjOedl6zi8zni6qcinJkZ27+P7LCHEET8rGdBRBAoGBAI/ZiVcmQiu9FtjM8lGdCOlOKnkvDxzRqpu8mglmwD+Nuy6a1TSotrzgSwryzALi/5Muaj/FXALEhJt91mXRh4QL9BX7cFxb/g94r05Etwj1z5D8yn9nqXtIorluPZtC5Rh22prI1FgoYzDD4EK23XwiUzcVW5Nio89glZ1aweRK",
//异步通知地址
'notify_url' => "http://houtt.skfa.com/index/user/notify_url",
//同步跳转
'return_url' => "http://houtt.skfa.com",
//编码格式
'charset' => "UTF-8",
//签名方式
'sign_type'=>"RSA2",
//支付宝网关
'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
//支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
'alipay_public_key' => "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA9H5INi43hujkxMaXjFx9YsCX82luk20r6BAdlkDDNHe2ffVxWgbzmUqrir4tD6ooiWyQNqgRBbUFP7aowiHQfjpfqRijt4nAni2MDh9XfUOuv4xEC8HnVMZNlYhF9RQ4nEbk3v6jMrA7qgi1p01IV5+axvjmh4+uYRTNJnpvnTEVRoRuRsx7e+uYTwUHgvMdTB6X+a79ZFUOrP/qlgfe71evIGL3T3BucqUtSG4CLR+YoviFZ8C5/cl/3p2Y0D2zNgOdakHOJRNJ2Kmf73URmxxVLWmGisYiYmWKaacivOjZMBPnbO6MmbcU5YPaeUm/emc1uz5y+eP6dwU03CSrywIDAQAB",
],
~~~
```
## 控制器引用 和回调 , 同步回调必须外网可以访问 , 异步回调也是
![](https://img.kancloud.cn/7f/7d/7f7d3dcfb9ae85b4022388789fd6b56b_1268x3635.png)
```
~~~
//支付宝网页支付
public function pay_money(){
$info = $_POST;
$price_info = Db::name('price')->where('id','=',$info['price_id'])->find();
$aop = new AopClient();
$config = config('alipay');
$aop->gatewayUrl = $config['gatewayUrl']; //网关地址要使用沙箱网关alipaydev
$aop->appId = $config['app_id'];
$aop->rsaPrivateKey = $config['merchant_private_key'];
$aop->format = "json";
$aop->apiVersion = '1.0';
$aop->postCharset='UTF-8';
$aop->signType = "RSA2";
//$aop->alipayrsaPublicKey = '填写沙箱页面给你的支付宝公钥';
//实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.app.pay
$request = new AlipayTradePagePayRequest();
//SDK已经封装掉了公共参数,这里只需要传入业务参数
$info = json_encode(['body'=>$info['user_id'],'subject'=>$info['price_id'],'out_trade_no'=>md5(time()),
'timeout_express'=>'30m','total_amount'=>$price_info['price'],'product_code'=>'FAST_INSTANT_TRADE_PAY'],JSON_UNESCAPED_UNICODE);
$request->setBizContent($info);
$request->setReturnUrl('http://houtt.skfa.com');
$request->setNotifyUrl('http://houtt.skfa.com/index/user/notify_url');
$result = $aop->pageExecute($request);
return $result;
}
public function notify_url(){
import('alipay.aop.AopClient');
$config = config('alipay');
$aop = new AopClient();
$aop->appId = $config['app_id'];
$aop->rsaPrivateKey = $config['merchant_private_key'];
$aop->alipayrsaPublicKey = $config['alipay_public_key'];
$aop->signType = $config['sign_type'];
$result = $aop->rsaCheckV1($_POST,'',$config['sign_type']);
if ($result) {
if($_POST['trade_status'] == 'TRADE_SUCCESS' || $_POST['trade_status'] == 'TRADE_FINISHED') {
$price_info = Db::name('price')->where('id','=',$_POST['subject'])->find();
Db::name('user')->where('id','=',$_POST['body'])->setInc('allow_num',$price_info['num']);
$insert_info['user_id'] = '2';
$insert_info['money'] = $_POST['total_amount'];
$insert_info['price_id'] = $_POST['subject'];
$insert_info['createtime'] = time();
Db::name('user_money_log')->insert($insert_info);
return 'success';
}
Log::write('trade_status is error:'.input('trade_status'));
return 'fail';
}
Log::write('sign verify is error:'.var_export($_POST));
return 'fail';
}
~~~
```
- tp5图片上传
- 文件上传到七牛云
- 上传到阿里云
- 富文本编辑器
- phpexcel和spreadsheet
- phpexcel导出
- phpexcel导入
- spreadsheet
- tp5_api接口
- 跨域请求
- JWT
- 图片和视频上传接口
- 验证码
- tp5小程序登录
- tp5小程序支付
- tp5基础架构
- 验证层
- 模型层Model
- 控制器构找
- tp5.0支付宝
- 海报二维码
- 轮播图
- echarts柱状图
- layui的图片弹窗
- p标签显示指定行数(全部)
- jquery和layerdate调用日期
- ajax发送文件和图片的坑啊
- JS日期点击上一天和下一天
- 百度分享js
- POST请求
- 商品数据表
- tp5.0支付宝最全
- tp5路由的坑
- 二维数组排序
- tp5模型分组group错误
- 二维变一维数组
- 无限树形结构
- json对象转数组
- 模型关联查询
- tp5的模型获取器和字段设定
- 经纬度获取距离排序