tp5微信退款及回调

退款要注意的地方
1、证书的路径–证书在商户平台下载并放在public里面引用即可
2、退款回调地址-在商户平台设置,不带参数
3、金额都要x100变元为分
4、商户退款单号out_refund_no–自定义-相当于支付时订单号
5、微信单号transaction_id–在支付回调时需要返回存储的参数,见另一篇小程序支付回调方法
6、商户订单号out_trade_no和微信单号transaction_id任选其一,我只用了transaction_id没有报错

 //退款
    //@param    order_id订单号
    public function refund()
    {
   
        $token=input('post.token');
        $res=checkToken($token);
        if($res ==90001){
   
            $order_id=input('post.order_id');
            $info=Db::name('order')->where('order_id',$order_id)->find();
            if ($info['expire_time']< time()){
   
                $data['code']=5;
                $data['msg']='订单已过期';
                $data['date']=null;
                return json($data);
            }
            $result=Db::name('refund')->where('order_id',$order_id)->find();
            if ($result){
   
                $data['code']=4;
                $data['msg']='您已申请退款,请勿重复申请';
                $data['date']=null;
                return json($data);
            }
            $res1=$this->refundOrder($order_id,$info);
            if ($res1){
   
                $appid=config('base.web_appid');
                $mch_id=config('base.wev_mch_id');
                $key=config('base.web_appsecret');
                $apiKey=config('base.web_apiKey');
                $wxPay = new WxpayService($mch_id,$appid,$key,$apiKey);
                $order_no=$order_id;//退款的订单号
                $total_fee=intval($info['amount']*100);;//订单金额
                $refund_fee=intval($res1['amount']*100);//退款的金额
                $transaction_id=$info['transaction_id'];
                $notify_url='https://域名/xxx/xx/xx/refundNotify';
                $result= $wxPay->wx_refund($appid,$mch_id,$order_no,$notify_url,$total_fee,$refund_fee
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值