1. 程式人生 > >支付寶介面的使用自己呼叫

支付寶介面的使用自己呼叫

public function payDo( Request $request ){
o r d e r n o =

i n p u t : : g e t (
o r d e r n o
) ; i f ( e m p t y ( order_no = input::get('order_no'); if( empty( order_no) ){
return redirect(‘OrderPayDo’);
}
$user = session(‘user’);
if( $request -> session() -> has(‘user’) ) {
//查詢訂單資訊
$where = [‘order_no’ => $order_no];
o r d e r = ( a r r a y ) D B : : t a b l e ( o r d e r ) > w h e r e ( order = (array)DB::table('order')->where( 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' );
    }

// }
}
注意:支付寶非同步通知地址必須寫