支付宝接口的使用自己调用
public function payDo( Request $request ){
order_no) ){
return redirect(‘OrderPayDo’);
}
$user = session(‘user’);
if( $request -> session() -> has(‘user’) ) {
//查询订单信息
$where = [‘order_no’ => $order_no];
where)->first();
if (empty($order)) {
return redirect(‘OrderPayDo’);
}
//私钥
$pri_key = ‘MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCqANK8JLSZ61NwOZdFSkp2x6pdR4+B7EEynqEHgIg5SGq429R4BeXanyQP9tgqidKKJZnaWggOEYEiZd+X5YxxKYpthjWIotvWwu/H+DxDxLGn6p8ys/xruut3xUTXX2l9pD8bCxNOaH3gi5Oy8HHoI7BefRg4uIFmqXePAgJd01mPRJQm7CHGMJMfoCDjq/sEzMdHy09Q6bFIgGZvQnWXoLAwRKHTiKOLDxz3Vw2j2HmfQHUzSVak/vjSvdZyZamAa19Zj+rPIYANmrcqIaKJssDZ7sY6ZR5gPy+ZlcKxPtGYg7SSt1KWQJBdsAU2CMr1S+OVQh0qkyYf6C6l01lTAgMBAAECggEAG4Rml+2ZDhD5QIER6zVLOE65VL/wiqcjJn5mskArzJncLG/oxESwH+MCg1MBSmFkotfTP3SzORO8Q0UaHAwb33VJ4tCGecdirjB/f26+0nlUCEoB2sMnaIio9IoJypK3EI81Z7szNM3VEjOFhMFGrryYH7M/6G51A5kKsSsyFt2Kk/hJU/lmXc7d1WLpaSbkqHtOUXI4D0m81p5muF10XTMPOeGRuehJqoYOP0bJ7uqg1soLtzBqpg5cuEePCsBr1y3eQsArm/UhDQlmwVbs9mWKQLYW/MpAH725T/JJ70CbAp6CVyMd0uCZ0yV4VLZEzQ3KgB0MHuZwEiC5Pr5WgQKBgQDz/dzBifXEB2PVPBfcuugaURF8AoieF66kVYbuNLzHPQvOu9IETjxY4UvB9UEqWFcygIapyDvfK8xnYvvshQokqUq/RLlWz5XMmwR5ZYGC1HcLOAQREDAipQakcgtFVdwJ60NpBpflNdmGCAzZbrZVLk812p1+cpkQbjt4Xt2chQKBgQCyXsEVHdyh6k4yyBl6T8GdJUC6jXPi/0TMEl2KNo9pwLmmEM8BP/CxsLhVFm2zqf7GHtllc6QCtTcidXIyE5jA5GhQI4x7YTeZI5C+eWMoRGy7RgLZAT97ruq217gzLx0HsgqBFRCihFmbClw7wAUBeVBJAFlqsJQsRMTDaxKR9wKBgQCZeqJH2EmRovhopOF5xtTD4ST3dfyMPedsliRHaUMqrTrlM357mN8bJbVq76SrR2CqcvDCkiMfUkTE8B36fQGRaDCNumQ/uFrJluWsm25pZs7vbrAYL6+ny1kvTlHKrqS4VJZV1YDs/P+08RFsINlvIa9P+BHD/cBM9ppQMJSEpQKBgEuKO4Vg5y6fV0zEV53oJxwRSc931otdBlrSsFC3eJcV6sm8tp5V4O6v4/ENFZqQNPjc2b7QcbY/3sC2Mo2opPmUAeVmmLkr2+r8F/HC4M6N4+qP5ObYU3VjB741r6nlmwrGSRKPxEK/gF9bzOH1GWmdYfX4suWvMKFq4lXMg8nTAoGASks6SurmlocTpaKJmaY2UmctNaERkt2lN94mI41bM+yjfgpqDTMe6dGIvhwqNIAl0zbPXxESM7kFj3ukoTzRv0sZb7FmhYRol2Zt1gV8dSV6GxjnuiS+21i/ClFLbJ2Rtb0jS45J0A1GWDX++Z2YGfl0ngbCWUv1+w5r75KAGu4=’;
//支付请求路径
$url = ‘https://openapi.alipaydev.com/gateway.do’;
//公共参数请求
$params = [
‘app_id’ => ‘2016091700535066’,//支付宝分配给开发者的应用ID
‘method’ => ‘alipay.trade.wap.pay’,// 接口名称
‘return_url’ => ‘http://www.shop.com/PayWin’,//同步跳转 HTTP/HTTPS开头字符串
‘charset’ => ‘utf-8’,//请求使用的编码格式,如utf-8,gbk,gb2312等
‘sign_type’ => ‘RSA2’,// 商户生成签名字符串所使用的签名算法类型,目前支持RSA2和RSA,推荐使用RSA2
// ‘sign’ => ‘’,//签名
‘timestamp’ => date(‘Y-m-d H:i:s’),//发送请求的时间,格式"yyyy-MM-dd HH:mm:ss"
‘version’ => ‘1.0’,// 调用的接口版本,固定为:1.0
‘notify_url’ => ‘http://188.131.131.120/callback.php’,//异步通知 支付宝服务器主动通知商户服务器里指定的页面http/https路径。
‘biz_content’ => ‘’ // 业务请求参数的集合,最大长度不限,除公共参数外所有请求参数都必须放在这个参数中传递,具体参照各产品快速接入文档
];
//业务请求参数
$pai_params = [
‘subject’ => ‘商品测试’,//标题
‘out_trade_no’ => $order_no,//订单号
‘total_amount’ => $order[‘order_amount’],// 订单总金额,单位为元,精确到小数点后两位,取值范围[0.01,100000000]
‘product_code’ => ‘QUICK_WAP_WAY’//销售产品码,商家和支付宝签约的产品码。该产品请填写固定值:QUICK_WAP_WAY
];
$json_api_params = json_encode($pai_params , JSON_UNESCAPED_UNICODE);//转换成json串,JSON_UNESCAPED_UNICODE汉字输出
$params['biz_content'] = $json_api_params;//添加到公共参数请求
//1.筛选并排序 按照键名第一个字母排序
ksort($params);
//2.拼接 将排序后的参数与其对应值,组合成“参数=参数值”的格式,并且把这些参数用&字符连接起来,此时生成的字符串为待签名字符串。
$url_params = http_build_query($params);//urlencold 编码
$str = urldecode($url_params);//urldecode 转码
//生成签名
$obj = new Rsa();
$sign = $obj -> rsaSign( $str , $pri_key );
//4.把生成的签名赋值给sign参数,拼接到请求参数中。
header( 'location:' . $url. '?' . $url_params . '&sign='. urlencode($sign));
}else{
return redirect( 'Login' );
}
// }
}
注意:支付宝异步通知地址必须写