实现支付宝退款 

http://www.upwqy.com/details/85.html

想要实现退款,前提是有支付的订单。所以这里也列举出来了支付 

 

1 支付宝配置

2 支付宝支付

3 支付宝退款

 

 

1 支付宝配置

可以查看 支付宝(新版)配置

2 支付 

文章待更新。。

3 退款

官方文档 https://docs.open.alipay.com/api_1/alipay.trade.refund

把配置弄好 基本是直接成功了。

 

需要注意的是  在文档上说的 商户的操作编号还有下面的几个参数 是可选的,但其实是不能删除的

 

我开始是直接把 operator_id store_id terminal_id  参数删除掉了。测试的结果一直是返回参数错误,请教了一个QQ谈论群的人 才知道,虽然这里说的是可选的 但是不能够直接删除掉,还是需要在参数中展现。。坑死我了快,白白浪费了两天的时间。。

 

这里非常感谢 帮助我解决这个坑的朋友,,真的是太感谢,要不然还不知道要弄多久呢。

 

其中 trade_no  支付宝交易号可以 去掉。

 

 

 

image.png

 

  /**
     * 支付宝 退款
   * @user 一秋
    * @param $out_trade_no
     * @param $refund_amount
     * @return bool
     * @throws Exception
     */
    public static function AliPayPlaceRefund($out_trade_no,$refund_amount){
        $refund_order = generateOrderId(9);
        $aop = new \AopClient ();
        $aop->gatewayUrl =  config('alipay.gatewayUrl');
        $aop->appId = config('alipay.appId');
        $aop->rsaPrivateKey = config('alipay.rsaPrivateKey');
        $aop->alipayrsaPublicKey = config('alipay.alipayrsaPublicKey');
        $aop->apiVersion = '1.0';
        $aop->signType = 'RSA2';
        $aop->postCharset='utf-8';
        $aop->format='json';
        $request = new \AlipayTradeRefundRequest();
        $request->setBizContent("{" .
//            "\"trade_no\":\"2017112821001004030523090753\"," .
            "\"out_trade_no\":\"$out_trade_no\"," .
            "\"refund_amount\":$refund_amount," .
            "\"refund_reason\":\"正常退款\"," .
            "\"out_request_no\":\"$refund_order\"," .
            "\"operator_id\":\"OP001\"," .
            "\"store_id\":\"NJ_S_001\"," .
            "\"terminal_id\":\"NJ_T_001\"" .
            "  }");

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

        if(!empty($resultCode)&&$resultCode == 10000){
//            echo "成功";
            return true;
        } else {
//            echo "失败";
            throw new Exception($result->$responseNode->sub_msg);
        }
    }

 

版权声明:本文为wqy415原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:http://www.cnblogs.com/wqy415/p/7977776.html