微信退款

<?php
namespace app\index\controller;

require_once "extend/wx/lib/WxPay.Api.php";
require_once 'extend/wx/example/WxPay.Config.php';
use app\common\controller\Api;
use app\admin\model\Article;
use think\Request;

class Refund extends Api
{
    public function _initialize()
    {
        parent::_initialize();
    }

    
    public function wxRefund()
    {
        $config = new \WxPayConfig();
        $merchid = $config->GetMerchantId();
        
        $input = new \WxPayRefund();
        $input->SetOut_trade_no('');          //自己的订单号
        //$input->SetTransaction_id('');    //微信官方生成的订单流水号,在支付成功中有返回
        $input->SetOut_refund_no(uniqid());            //退款单号
        $input->SetTotal_fee('20'); //0.2           //订单标价金额,单位为分
        $input->SetRefund_fee('20');           //退款总金额,订单总金额,单位为分,只能为整数
        $input->SetOp_user_id($merchid);                        //商户号
        $result = \WxPayApi::refund($config,$input); //退款操作
        
     
        return $result;
    }
}
//=======【证书路径设置-需要业务方继承】=====================================
	/**
	 * TODO:设置商户证书路径
	 * 证书路径,注意应该填写绝对路径(仅退款、撤销订单时需要,可登录商户平台下载,
	 * API证书下载地址:https://pay.weixin.qq.com/index.php/account/api_cert,下载之前需要安装商户操作证书)
	 * 注意:
	 * 1.证书文件不能放在web服务器虚拟目录,应放在有访问权限控制的目录中,防止被他人下载;
	 * 2.建议将证书文件名改为复杂且不容易猜测的文件名;
	 * 3.商户服务器要做好病毒和木马防护工作,不被非法侵入者窃取证书文件。
	 * @var path
	 */
	public function GetSSLCertPath(&$sslCertPath, &$sslKeyPath)
	{
		$sslCertPath = getcwd().'\public\cert\apiclient_cert.pem'; //放在可以访问的路径下如果是框架的话
		$sslKeyPath = getcwd().'\public\cert\apiclient_key.pem';
	}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

饭饭咿呀呀

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值