laravel使用easywechat开发退款

1 . 退款

$app    = Factory::payment($this->pay_config);//pay_config 微信配置
//根据商户订单号退款
$app->refund->byOutTradeNumber(string $number, string $refundNumber, int $totalFee, int $refundFee, array $config = []);

// Example:
$result = $app->refund->byOutTradeNumber('out-trade-no', 'refund-no-xxx', 20000, 1000, [
    // 可在此处传入其他参数,详细参数见微信支付文档
    'refund_desc' => '退款',
    'notify_url'    => 'http://'.$this->host.'/weixin/refundBack',
]);

 

out-trade-no 商户订单号,refund-no 退款订单号

注意:退款金额的单位是分

2.退款成功通知

示例代码

    public function refundBack(){
        $app    = Factory::payment($this->pay_config);
        $response = $app->handleRefundedNotify(function ($message, $reqInfo, $fail) {
            // 其中 $message['req_info'] 获取到的是加密信息
            // $reqInfo 为 message['req_info'] 解密后的信息
          
            $order = Order::where('order_sn',$reqInfo['out_trade_no'])->first();

            if (!$refund_info || $refund_info->status=='1') { // 如果订单不存在 或者 订单已经退过款了
                return true; // 告诉微信,我已经处理完了,订单没找到,别再通知我了
            }
            if($message['return_code']=='SUCCESS'){
                $update_data = [];
                if($reqInfo['refund_status']=='SUCCESS'){
                   
                }else{
                    
                }
                
            }
            return true; // 返回 true 告诉微信“我已处理完成”
            // 或返回错误原因 $fail('参数格式校验错误');
        });

        return $response;
    }
$message 和  $reqInfo 数据内容
//$message
array (
  'return_code' => 'SUCCESS',
  'appid' => 'wx****',
  'mch_id' => '****',
  'nonce_str' => '49bb7b676af7c4ac13987095817eb655',
  'req_info' => '5YbETX1lmnze3rqH/sLX56Qh/3lFi/kzTRJpB+/+HIINrRbo7+hNsr5cXJaLc8Egqrbs+hGbp2ek4yp8cb+XK+a/dnK9UYvEq9u+J8LMCBW5bhaO7ReplHWK8Epxw8F0UnRPJUFKywLwHOdLQGFEMwoEgM92td0PaT4iObYp4mlb8BTe4b3oxN5bUXBYu8B8sFOXzHuHmO8GNjlYPCNNftSjV2BSCz2X9toPzxuhklk3oy8kxYjruzPGj6WtmcvFLx7Xy3Y2hleu2hhaOZ8/kn3FmG6ql2lnMIaq+z2wYeEY3xoy2dA9yx7DgvpNoL89/CDiCQtFhiZcAt3+dzi42dNQ6N9p/8102F9f6jaESFXocitsZCsxPDruRO+/evXi8JOhwu9qfTgSw1pq1ZkgNGRP0AV6GVf98HIjV0TGYcJOcAFqc9D+wNkzMZi7uyDvtuoMr2XiaNDY0l8cP7mkCK3MFypbCLlLuD6smkqamVggdM1ppf8rWhcWlWukUP8e9h/+M9+xLDfOTNV2KXPpQHCf3MiFzAzcyGXNdfPMaxLJ+Xzzos8Zu1r5Jvek+Ab3Rz6hc06vawsvsDE8RD7sI0gN4+sG2dJ6Ssfp1bWVnc6Nl882x4TZc8s+DA4M8ULfPgK/rmnQ8831YsJCZK9T7t/H36qjB1xraaCcZX9z+LFP1eUbcTRvWs39QEzjXJPpuLOoeHVBoNzM1iHqPf/c5DN2r7wnwH/ihvrW08VKWMXTrSYDW5seOBNbx0i5QMEQO7qBdVtj5vOrUqSuz0vABhppIvKn3MgVmycOqfno9SF4r7d09FhS6lUzsXCNu7Q6nNUWWMXZF8Lwy94RXN4hvyH1rHlRl2KuIl/rMMCiiXG6MbUxbbhIqx6tof6N11U0ws73u89v3C+Qm+tuELOpbDsnz38L91jyBkVJTgdVGACWQAzwfJmfRIZTf2A2OTnkoUhe/BLeKNstY0LZdH0miPnSGtL4bPWrYfolg1+P5OqOedH2NV39BEc0becIYzDb+zo0KB3M8Vs1KpXLtD59CI=',
)  
//$reqInfo
array (
  'out_refund_no' => 'r2018******38511',
  'out_trade_no' => '2018*****8290675',
  'refund_account' => 'REFUND_SOURCE_UNSETTLED_FUNDS',
  'refund_fee' => '1',
  'refund_id' => '5000040830678091106300227403',
  'refund_recv_accout' => '支付用户零钱',
  'refund_request_source' => 'API',
  'refund_status' => 'SUCCESS',
  'settlement_refund_fee' => '1',
  'settlement_total_fee' => '1',
  'success_time' => '2018-08-11 17:11:24',
  'total_fee' => '1',
  'transaction_id' => '4200000180201809116557984948',
)  

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值