thinkphp5调用支付宝商户号提现给用户

本文详细介绍了如何使用支付宝提供的API实现自动提现功能。包括配置支付宝网关、设置应用密钥等关键步骤,并展示了如何通过PHP代码发起提现请求及处理响应结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

$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;
    }
}

  

转载于:https://www.cnblogs.com/qhorse/p/9455537.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值