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

 

 

 posted on 2020-05-06 16:39  三哥-Noble  阅读(437)  评论(0编辑  收藏  举报
TOP