| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?php
- //微信支付相关的处理
- namespace common\components;
- use Yii;
- class wpPayUtil
- {
- //退款
- //https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_4
- /**
- * @param $out_trade_no 支付时的订单号(零售端订单号)
- * @param $total_fee 支付时金额
- * @param $refund_fee 退款金额
- * @param $out_refund_no 退款订单
- * @param $appid
- * @param $mchid
- * @param $notify_url 回调地址
- * @return bool|\成功时返回,其他抛异常
- */
- public static function refund($out_trade_no,$total_fee,$refund_fee,$out_refund_no,$appid,$mchid,$notify_url)
- {
- try{
- ini_set('date.timezone','Asia/Shanghai');
- error_reporting(E_ERROR);
- $wx = Yii::getAlias("@vendor/weixin");
- require_once($wx . '/lib/WxPay.Api.php');
- $input = new \WxPayRefund();
- $input->SetOut_trade_no($out_trade_no);
- $input->SetTotal_fee($total_fee);
- $input->SetRefund_fee($refund_fee);
- $input->SetOut_refund_no($out_refund_no);
- $input->SetOp_user_id($mchid);
- $input->SetNotify_url($notify_url);
- $res = \WxPayApi::refund($input,6,$appid,$mchid);
- Yii::info("退款返回信息: ",$res);
- return $res;
- }catch (\Exception $exception){
- Yii::warning("退款返回信息: ",$exception->getMessage());
- }
- return false;
- }
- }
|