### 微信退款
**位置:**
Common\Lib\WechatLib.class.php
**参数:**
* @param $refund_params array 微信退款需要的参数数组
**调用:**
* 组件文件外调用
$my_wx = new WechatLib(); // 实例化微信组件库类
$refund_params = array(
'out_trade_no' => '1OS2018122445',
'total_fee' => '200',
'refund_fee' => '50',
'refund_order_no' => 'fanfanfan'
);
$res = $my_wx->wxRefund($refund_params);
**返回:**
成功时返回
Array
(
[appid] => wx63e9531e049c102c
[cash_fee] => 200
[cash_refund_fee] => 50
[coupon_refund_count] => 0
[coupon_refund_fee] => 0
[mch_id] => 1338026401
[nonce_str] => hJbinYV2oEpMmFHv
[out_refund_no] => fanfanfan
[out_trade_no] => 1OS2018122445
[refund_channel] => Array
(
)
[refund_fee] => 50
[refund_id] => 50000609162018122507684961139
[result_code] => SUCCESS
[return_code] => SUCCESS
[return_msg] => OK
[sign] => 1ADD203674A7C7D3C22422970C7080825B834DDF091ED688BD1785B44FB74392
[total_fee] => 200
[transaction_id] => 4200000248201812241034543566
)
失败时候返回
详见微信申请退款API文档
https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_4
**完整代码:**
~~~
/**
* @param $refund_params退款参数数组
* 例:
* $refund_params = array(
* 'out_trade_no' => '1OS2018122445',
* 'total_fee' => '200',
* 'refund_fee' => '50',
* 'refund_order_no' => 'fanfanfan'
* );
* @return 成功时返回退款成功信息,不成功返回错误信息
*/
public function wxRefund($refund_params) {
require_once APP_PATH."Common/Plugins/Wxpay/lib/WxPay.Api.php";
require_once APP_PATH."Common/Plugins/Wxpay/example/WxPay.Config.php";
require_once APP_PATH."Common/Plugins/Wxpay/example/log.php";
if((isset($refund_params["transaction_id"]) && $refund_params["transaction_id"] != ""
&& !preg_match("/^[0-9a-zA-Z]{10,64}$/i", $refund_params["transaction_id"], $matches))
|| (isset($refund_params["out_trade_no"]) && $refund_params["out_trade_no"]!=""
&& !preg_match("/^[0-9a-zA-Z]{10,64}$/i", $refund_params["out_trade_no"], $matches))
|| (isset($refund_params["total_fee"]) && $refund_params["total_fee"] != ""
&& !preg_match("/^[0-9]{0,10}$/i", $refund_params["total_fee"], $matches))
|| (isset($refund_params["refund_fee"]) && $refund_params["refund_fee"] != ""
&& !preg_match("/^[0-9]{0,10}$/i", $refund_params["refund_fee"], $matches)))
{
header('HTTP/1.1 404 Not Found');
exit();
}
if(isset($refund_params["out_trade_no"]) && $refund_params["out_trade_no"] != ""){
$out_trade_no = $refund_params["out_trade_no"];
$total_fee = $refund_params["total_fee"];
$refund_fee = $refund_params["refund_fee"];
$refund_order_no = $refund_params["refund_order_no"];
$input = new \WxPayRefund();
$input->SetOut_trade_no($out_trade_no);
$input->SetTotal_fee($total_fee);
$input->SetRefund_fee($refund_fee);
$config = new \WxPayConfig();
$input->SetOut_refund_no($refund_order_no);
$input->SetOp_user_id($config->GetMerchantId());
$result = \WxPayApi::refund($config, $input);
return $result;
}
}
~~~
- 模版
- 前言
- 项目架构
- 项目规范
- HTML
- CSS
- Javascript
- PHP
- MySQL
- 注意规范
- 开发版本管理
- 开发流程
- 系统配置
- 阿里云服务器配置
- 计划任务配置说明
- 开发示例
- Page分页
- Search_param搜索结果赋值
- Add新增
- Edit编辑
- Ajax表单验证
- Ajax二级联动
- Excel 导出数据首位不去0的方法
- POS总部控制
- 下载CSV格式的模板
- 订单唯一码表和订单SKU表实收金额生成
- 快捷日期选择
- JS函数
- ajax_send
- ajax_result
- createQrCodes
- createBarCodes
- printTpl
- JS插件
- BootstrapValidator表单验证插件
- Address省市区插件
- Bootstrap-datepicker日期插件
- Bootstrap-select多选框插件
- Toastr消息提示插件
- PalyAudit扫描声音提示插件
- WebUploader多图片上传插件
- Ueditor富文本编辑器插件
- Function
- alert
- object_to_array
- array_to_object
- get_address
- set_param_url
- get_shops_name
- get_user_name
- get_warehouse
- get_cheapest_sku
- print_attr(新)
- print_img(新)
- get_spu_no(新)
- get_type_name(新)
- get_brand_en(新)
- get_cat_name(新)
- get_attr_name(新)
- spu_cat_info(新)
- get_time_event_price
- get_vendors
- check_total_reduce
- check_total_discount
- get_inventory
- get_delivery
- get_sale_inventory
- get_customer_name
- phone_protection
- get_order_no
- get_event_name
- get_order_status
- get_item_status
- get_ditch_name
- get_card_no
- get_shop_sales
- get_pay_name
- get_season
- amt_format
- get_cat_parent
- print_attr_id
- round_bcadd
- round_bcsub
- round_bcmul
- round_bcdiv
- get_account_name
- Controller
- Common_BaseController
- check_membership_card
- get_menu_list
- importErrorMassage
- Wpos_IndexController
- get_customer_vip_card
- get_shops_id
- calculate_active_integral
- check_numbers_active
- check_goods_active
- Woms_IndexController
- Model
- View
- category
- cycle_date.html
- shop_select门店多选搜索框
- 品牌A-Z排序多选brand_mc.html
- 供应商代码A-Z排序vendor_no_mc.html
- Lib
- BuyerLib
- WarehouseLib
- EventLib
- getTimeEventPrice
- getVipType
- getEvent
- orderTotalEvent
- orderTimeEvent
- getTotalReduce
- getTotalDiscount
- SaleLib
- CustomerLib
- addCustomerService
- GiftcardLib
- WechatLib
- wxRefund
- OrdersLib
- orderLog
- calculatePayinAmount
- calculateSubtotal
- correctPayinAmount
- saveOrderAddress
- getOrderAddress
- setDeliveryNo
- SyncLib
- updateOuterStock
- UserLib
- createCommission
- FlowLib
- orderList
- addOrder
- addLog
- orderInfo
- checkSku
- orderSave
- orderStop
- orderExecute
- skuEdit
- orderPrinta
- scanGoods
- boxClose
- orderOut
- take
- bview
- check
- deliveryStatus
- checkGoods
- GoodsLib
- createGoodsNo
- createNewGoodsNo
- getSystemStyleNo
- getDim
- MallLib
- smsLog
- GoodsBaseLib
- getBrandInfo
- getBrandsInfo
- getAttrIdArray
- getPrintAttr
- getMustAttr
- getCatIdInfo
- valTypeId
- valsTypeId
- getCatNoInfo
- getCatInfo
- getAttrArr
- getAttrInfo
- getValInfo
- getAttrId
- getValId
- getAttrSeaon
- getValueId
- PointsLog
- pointsIn
- pointsUp
- EcGoodsLib
- getSkuInventory
- Tools
- CsvTools
- csvImport
- csvExport
- ExcelTools
- importExcel
- exportExcel
- exportHeadExcel
- MailTools
- SmsTools
- sendMessage
- UploadTools
- ExportTools
- exportData
- TaobaoTools
- getOnsaleItems
- getSkusItems
- PicturesTools
- uploadPicture
- Plugins
- WxBase
- Taobao
- 问题反馈