<?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';
}