Example #1
0
 /**
  * 
  * 申请退款,WxPayRefund中out_trade_no、transaction_id至少填一个且
  * out_refund_no、total_fee、refund_fee、op_user_id为必填参数
  * appid、mchid、spbill_create_ip、nonce_str不需要填入
  * @param base\WxPayRefund $inputObj
  * @param int $timeOut
  * @throws WxPayException
  * @return 成功时返回,其他抛异常
  */
 public static function refund($inputObj, $timeOut = 6)
 {
     $url = "https://api.mch.weixin.qq.com/secapi/pay/refund";
     //检测必填参数
     if (!$inputObj->IsOut_trade_noSet() && !$inputObj->IsTransaction_idSet()) {
         throw new WxPayException("退款申请接口中,out_trade_no、transaction_id至少填一个!");
     } else {
         if (!$inputObj->IsOut_refund_noSet()) {
             throw new WxPayException("退款申请接口中,缺少必填参数out_refund_no!");
         } else {
             if (!$inputObj->IsTotal_feeSet()) {
                 throw new WxPayException("退款申请接口中,缺少必填参数total_fee!");
             } else {
                 if (!$inputObj->IsRefund_feeSet()) {
                     throw new WxPayException("退款申请接口中,缺少必填参数refund_fee!");
                 } else {
                     if (!$inputObj->IsOp_user_idSet()) {
                         throw new WxPayException("退款申请接口中,缺少必填参数op_user_id!");
                     }
                 }
             }
         }
     }
     $inputObj->SetAppid(WxPayConfig::APPID);
     //公众账号ID
     $inputObj->SetMch_id(WxPayConfig::MCHID);
     //商户号
     $inputObj->SetNonce_str(self::getNonceStr());
     //随机字符串
     $inputObj->SetSign();
     //签名
     $xml = $inputObj->ToXml();
     $startTimeStamp = self::getMillisecond();
     //请求开始时间
     $response = self::postXmlCurl($xml, $url, true, $timeOut);
     $result = WxPayResults::Init($response);
     self::reportCostTime($url, $startTimeStamp, $result);
     //上报请求花费时间
     return $result;
 }
Example #2
0
    $input->SetTotal_fee($total_fee);
    $input->SetRefund_fee($refund_fee);
    $input->SetOut_refund_no(WxPayConfig::MCHID . date("YmdHis"));
    $input->SetOp_user_id(WxPayConfig::MCHID);
    printf_info(WxPayApi::refund($input));
    //$payApi=new WxPayApi();
    exit;
}
//$_REQUEST["out_trade_no"]= "122531270220150304194108";
///$_REQUEST["total_fee"]= "1";
//$_REQUEST["refund_fee"] = "1";
if (isset($_REQUEST["out_trade_no"]) && $_REQUEST["out_trade_no"] != "") {
    $out_trade_no = $_REQUEST["out_trade_no"];
    $total_fee = $_REQUEST["total_fee"];
    $refund_fee = $_REQUEST["refund_fee"];
    $input = new WxPayRefund();
    $input->SetOut_trade_no($out_trade_no);
    $input->SetTotal_fee($total_fee);
    $input->SetRefund_fee($refund_fee);
    $input->SetOut_refund_no(WxPayConfig::MCHID . date("YmdHis"));
    $input->SetOp_user_id(WxPayConfig::MCHID);
    printf_info(WxPayApi::refund($input));
    exit;
}
?>
<body>  
	<form action="#" method="post">
        <div style="margin-left:2%;color:#f00">微信订单号和商户订单号选少填一个,微信订单号优先:</div><br/>
        <div style="margin-left:2%;">微信订单号:</div><br/>
        <input type="text" style="width:96%;height:35px;margin-left:2%;" name="transaction_id" /><br /><br />
        <div style="margin-left:2%;">商户订单号:</div><br/>