退款要注意的地方
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