yansongda 支付寶商家轉賬給使用者

strmsg發表於2022-01-19
開發框架: laravel:8
通過composer下載:   composer require yansongda/pay:^2
//支付寶官方線上生成證照地址 重點:(生成祕鑰-》模式-》選擇:公鑰證照)
https://miniu.alipay.com/keytool/match
//遇到的問題
//因為yansongda 使用的是     
alipay.fund.trans.uni.transfer  轉賬介面 ( 強制公鑰證照,下面配置中的 ali_public_key 引數 )
ERROR_GATEWAY: Get Alipay API Error:Invalid Arguments - isv.missing-app-cert-sn
//證照籤名錯誤
ERROR_GATEWAY: Get Alipay API Error:Invalid Arguments - isv.invalid-signature
<?php
//支付配置 alipay.php
return [
    'alipay' => [
        // 支付寶分配的 APPID
        'app_id' => '你的支付寶appid',

        'sign_type' => 'RSA2',

        // 支付寶非同步通知地址
        'notify_url' => env("APP_URL").'/api/alipayMobileNotifyUrl',

        // 支付成功後同步通知地址
        'return_url' => env("APP_URL").'/api/alipayMobileNotifyUrl',

        // 使用公鑰證照模式,請配置下面兩個引數,同時修改 ali_public_key 為以 .crt 結尾的支付寶公鑰證照路徑,如(./cert/alipayCertPublicKey_RSA2.crt)
        //支付寶公鑰地址(預設沙箱通用公鑰,如需除錯線上環境請換成支付寶線上的公鑰:https://docs.open.alipay.com/291/106103/)
        'ali_public_key' => "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmFD6E1wuPtgw3wTZSbH0xt3CaSs/CKDKMfcwDRvx2tCsMH8X8S7LH2SwsTZMfhg7o9TxQH2+UUJhJHNqogHtWNO9V7ocGhou46e/myyLFA1a3+bjpH2Z9Y5bDZT1YQdC0TVUCnUdwjYBdrLmBwJS6UAso+DPw6jJLjVjyOB14koCPXIaHziggG+y0p+Y6c+a43hrLvYkFzcI8kauc5NPZdiMJKT1orFe4WN1IIgHE+fvAsTqcioImjWY+OSaIgWmYJdbBHbBybkZ3NkyHcno4zxKw0Gd4fbX98sob6qPrKUuHsy7SJhYn8oeAVDi9VuPbQlsVo8OtvCnpT65LS7fL5wIDAQasAB",

        //商戶私鑰地址(預設沙箱通用私鑰,如需除錯線上環境請換成線上的私鑰:https://docs.open.alipay.com/291/106103/)
        'private_key'=>"MIIEowIBAAKCAQEAmFD6E1wuPtgw3wTZSbH0xt3CaSs/CKDKMfcwDRvx2tCsMH8X8S7LH2SwsTZMfhg7o9TxQH2+UUJhJHNqogHtWNO9V7ocGhou46e/myyLFA1a3+bjpH2Z9Y5bDZT1YQdC0TVUCnUdwjYBdrLmBwJS6UAso+DPw6jJLjVjyOB14koCPXIHziggG+y0p+Y6c+a43hrLvYkFzcI8kauc5NPZdiMJKT1orFe4WN1IIgHE+fvAsTqcioImjWYas+OSaIgWmYJdbBHbBybkZ3NkyHcno4zxKw0Gd4fbX98sob6qPrKUuHsy7SJhYn8oeAVDi9VuPbQlsVo8OdtvCnpT65LS7fL5wIDAQABAoIBAFt4fcW0nP0WnbrA0bClEwd+U2sPEoqe7O42sP+eYY7ztARnvrwTSt5ufIHfxu4OpXpMvhjpqqpn/6iBO29RUvT+K34MgSXXxYLn0XRhup/vKTy/DsRQvW2u8NVmODntv12d9ftVu+pOvnBHHUbmSV5UMLq1nm+05CRA4czXp1OeCwcySx2Eo4h2F6faLWOBjoFVchME4SOXkOdxfBecSMuQHK+Vel5cj7vPQQlHJSZ+pvVkrgXYpzmKmLCDUCHOU8FJivdmFFtqvUCk4ARCRgZFktcaAcGaH8DGhnv9/P69XidhWrVKJsWU09qG5HCc7trmWAi+CjpXI1scdiOw+lECgYEAzNgN5aLlRklozNnHZmdiFkjznRb74bGpg3C6uMwVhiijdjgJHlCyxlOMivb1daAUTN3NgpFrD4yWt6wCEVuRby3WFJT5ELt42d6e1vUO/e2K9SxPeTv/0mU007XwNaQ1Wbn1VCzZ/R8KnboU5sJw8nVK+uws+Fw34xHup0OkkzkCgYEAvlrCttn5qUWJr/HA5PZ7I2tPPbz3YrGNxP4w6x1M+xUVuuvUltOfE+GPVVUXprC1cUNGQpCGZTt0+V5/i2pO8v1rQzZrmucgD+ROZlmdqh5RZKUEtJs8EhnzInneUGODpUF8qFi6ueOg1UJKgg5rgrnd3RKm7louE5LtUGvBuB8CgYAUuEHnmWuBiYldNyYROKHWSTjDCgEeWh8gWXW5nYML1+541cAuXdFHeEn+AG7hn/iNsd3IuDbREtJn77Eh2lZCnatK16q9w4i82OTOL2l9y9pDZGEBjU0aFfya8YtDkcGHuuSSyBqgnNQxEhJtKPvNuomECgGeeY15nWW7a38pGQKBgEyYcs9nCJn/XDcLHWZEdCo9bOZX2mfBMF27Nu30nVxPEK5lZObIArPaSHW6xsiRRIFt46C3TQ0BDsGlL8dmoJwQMxAZntT2+aTLZmyy1Ml2Z6QK7sjJyjMyc+5EgZtxX7ComEOZaJGSMc5+XULWEJbKuabScY9phC7mKU35/jpbAoGBAI9h6SvDC4wCjr7bmNCSjZcPIGJMTe8X2LtrdioFMZBMhhifdEDg6LeMZ2asLl0f5r5UQGck72z8wu1j8UrBC971qTXetwdw4hdKEOpUAjbWfCuthr+jGHHx+ZbgF7szwcIiKtOHzZlrTY3Rm7KadaOaYjO75amHX9SwlNlGD/j2",

        // 應用公鑰證照路徑
        'app_cert_public_key' => base_path('storage/cert/appCertPublicKey_2021003114639213.crt'),

        // 支付寶根證照路徑
        'alipay_root_cert'    => base_path('storage/cert/alipayRootCert.crt'),

        // 公鑰證照
        'ali_public_key'      => base_path('storage/cert/alipayCertPublicKey_RSA2.crt'),

        // 日誌
        'log' => [
            'file' => storage_path('logs/alipay.log'),
        ],

        // optional,設定此引數,將進入沙箱模式
        // 'mode' => 'dev',
    ],
];
// 處理提現邏輯 Withdrawal.php

                $order = 123456789; //提現訂單號
                $price = 100; //提現訂單金額
                $id    = 1; //提現訂單id
                //提現到支付寶
                $config = config('alipay.alipay'); //獲取alipay.php配置
                $aliOrder = [
                    'out_biz_no'      => $order,
                    'product_code'    => 'TRANS_ACCOUNT_NO_PWD',
                    'trans_amount'    => $price,
                    'biz_scene'       => 'DIRECT_TRANSFER',
                    'remark'          => '支付寶提現',
                    'payee_info'      => [
                        'identity'      => $binginfo["alipay"], //提現人支付寶
                        'identity_type' => 'ALIPAY_LOGON_ID',
                        'name'          => $binginfo["truename"] //提現人真實姓名
                   ]
                ];

                $result = \Yansongda\Pay\Pay::alipay($config)->transfer($aliOrder);
                //使用者的餘額記錄
                if (!($result['code'] == 10000 && $result['msg'] === 'Success')) {
                    writeLog('ali_pay_success', ['msg' => '支付寶提現失敗' . $order["order_num"], 'returnData' => $result]);
                    return $this->errorResponse($result['sub_msg']);
                }
                //提現成功處理邏輯(大家根據自己的邏輯處理就行了)
                DB::table("withdorder")->where("id", $id)
                    ->update(["desc" => $desc, "status" => $status, "update_time" => date("Y-m-d H:i:s")]);

                $log["user_id"]      = $user_id;
                $log["month_day"]    = date("m-d H:i");
                $log["amount_money"] = $price;
                $log["add_time"]     = date("Y-m-d H:i:s", time());
                $log["descript"]     = $descript;
                // 寫入餘額操作記錄
                Paymentsum::getPaylog($log);

            }
本作品採用《CC 協議》,轉載必須註明作者和本文連結

相關文章