thinkphp5調用支付寶商戶號提現給用戶


$out_biz_no = Tools::buildOrderNo();
$res = $this->userWithDraw($cash_id,$approve_status,$out_biz_no,$payee_account,$amount);




private function userWithDraw($cash_id,$approve_status,$out_biz_no,$payee_account,$amount)
{
    $ret = false;
    include(EXTEND_PATH.'/alipay/AopSdk.php');
    $payer_show_name = '付款人姓名';
    $remark = "您在XXX商城申請提現受理成功,商戶訂單號【".$out_biz_no."】,提現金額為".$amount."元,請在支付寶余額進行查看";
    $aop = new \AopClient();
    $aop->gatewayUrl =  'https://openapi.alipay.com/gateway.do';//支付寶網關 https://openapi.alipay.com/gateway.do這個是不變的
    $aop->appId = Config::get('custom.alipay.appId');//商戶appid 在支付寶控制台找
    $aop->rsaPrivateKey = Config::get('custom.alipay.rsaPrivateKey');//私鑰 工具生成的
    $aop->alipayrsaPublicKey = Config::get('custom.alipay.alipayrsaPublicKey');//支付寶公鑰 上傳應用公鑰后 支付寶生成的支付寶公鑰
    $aop->apiVersion = '1.0';
    $aop->signType = 'RSA2';
    $aop->postCharset='utf-8';
    $aop->format='json';
    $request = new \AlipayFundTransToaccountTransferRequest();
    $request->setBizContent("{" .
        "\"out_biz_no\":\"$out_biz_no\"," .
        "\"payee_type\":\"ALIPAY_LOGONID\"," .
        "\"payee_account\":\"$payee_account\"," .
        "\"amount\":\"$amount\"," .
        "\"payer_show_name\":\"$payer_show_name\"," .
        "\"remark\":\"$remark\"" .
        "}");

    $result = $aop->execute($request);

    $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
    $resultCode = $result->$responseNode->code;

    if(!empty($resultCode)&&$resultCode == 10000){
        //提現成功以后 更新表狀態
        //並且記錄 流水等等
        $cash_status = 1;
        F_PC::approveStatus($cash_id, $approve_status);
        $res = F_PC::cashStatus($cash_id, $cash_status);
        if (!$res) {
            //提現成功,狀態修改失敗
            $this->code = RetCode::FAILED;
            $this->mesg = '提現成功,狀態修改失敗';
            goto ret;
        }
        goto ret;
        ret:
        $res = $ret ? true : false;
        return $res;
    } else {
        //$result->$responseNode->sub_msg 這個參數 是返回的錯誤信息
       // $errorCode=json_decode(json_encode($result->$responseNode),TRUE);
        //提現失敗   寫入修改狀態提現失敗
        $cash_status = 2;
        $res = F_PC::cashStatus($cash_id, $cash_status);
        if (!$res) {
            //狀態修改失敗
            $this->code = RetCode::FAILED;
            $this->mesg = '狀態修改失敗';
            goto ret;
        }
        goto ret;

        $res = $ret ? true : false;
        return $res;
    }
}

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM