public function gotoRefund($out_trade_no, $refund_fee, $totle_fee) { if (!isset($out_trade_no) || !isset($refund_fee) || !isset($totle_fee)) { echo '订单号和退款金额为空!'; exit; } else { $out_trade_no = $out_trade_no; $refund_fee = $refund_fee; //商户退款单号,商户自定义,此处仅作举例 $out_refund_no = "{$out_trade_no}" . "01"; $total_fee = $totle_fee; //使用退款接口 $refund = new \Refund_pub(); $refund->setParameter("transaction_id", "{$out_trade_no}"); //商户订单号 $refund->setParameter("out_refund_no", "{$out_refund_no}"); //商户退款单号 $refund->setParameter("total_fee", "{$total_fee}"); //总金额 $refund->setParameter("refund_fee", "{$refund_fee}"); //退款金额 $refund->setParameter("op_user_id", WxPayConf_pub::MCHID); //操作员 $refundResult = $refund->getResult(); if ($refundResult["return_code"] == "FAIL") { echo "通信出错:" . $refundResult['return_msg'] . "<br>"; } else { echo "业务结果:" . $refundResult['result_code'] . "<br>"; echo "错误代码:" . $refundResult['err_code'] . "<br>"; echo "错误代码描述:" . $refundResult['err_code_des'] . "<br>"; echo "公众账号ID:" . $refundResult['appid'] . "<br>"; echo "商户号:" . $refundResult['mch_id'] . "<br>"; echo "子商户号:" . $refundResult['sub_mch_id'] . "<br>"; echo "设备号:" . $refundResult['device_info'] . "<br>"; echo "签名:" . $refundResult['sign'] . "<br>"; echo "微信订单号:" . $refundResult['transaction_id'] . "<br>"; echo "商户订单号:" . $refundResult['out_trade_no'] . "<br>"; echo "商户退款单号:" . $refundResult['out_refund_no'] . "<br>"; echo "微信退款单号:" . $refundResult['refund_idrefund_id'] . "<br>"; echo "退款渠道:" . $refundResult['refund_channel'] . "<br>"; echo "退款金额:" . $refundResult['refund_fee'] . "<br>"; echo "现金券退款金额:" . $refundResult['coupon_refund_fee'] . "<br>"; } } }
function refund($order_sn, $refund_fee) { $out_trade_no = $order_sn; //输入需退款的订单号 //商户退款单号,商户自定义,此处仅作举例 $time_stamp = time(); //$out_refund_no = "$out_trade_no"; $out_refund_no = "{$out_trade_no}" . "{$time_stamp}"; //总金额需与订单号out_trade_no对应,demo中的所有订单的总金额为1分 $order_info = order_info(0, $order_sn); //$total_fee = intval($order_info['money_paid']*100) ; $total_fee = intval($order_info['total_fee'] * 100); $refund_fee = intval($refund_fee); //使用退款接口 $refund = new Refund_pub(); //设置必填参数 //appid已填,商户无需重复填写 //mch_id已填,商户无需重复填写 //noncestr已填,商户无需重复填写 //sign已填,商户无需重复填写 $payment = get_payment('wxpay'); $refund->setParameter("appid", "{$payment['wxpay_app_id']}"); $refund->setParameter("mch_id", $payment['wxpay_mchid']); $refund->wxpay_key = $payment['wxpay_key']; /* $this->wxpay_app_secret = $payment['wxpay_app_secret']; $this->wxpay_mchid = $payment['wxpay_mchid']; $this->wxpay_key = $payment['wxpay_key']; $this->wxpay_paySignKey = $payment['wxpay_paySignKey']; */ //$refund->setParameter("out_trade_no","$out_trade_no"); //$refund->setParameter("out_trade_no","$out_trade_no"); $refund->setParameter("out_trade_no", "{$out_trade_no}"); //商户订单号 $refund->setParameter("out_refund_no", "{$out_refund_no}"); //商户退款单号 $refund->setParameter("total_fee", "{$total_fee}"); //总金额 $refund->setParameter("refund_fee", "{$refund_fee}"); //退款金额 $refund->setParameter("op_user_id", $payment['wxpay_mchid']); //操作员 //非必填参数,商户可根据实际情况选填 //$refund->setParameter("sub_mch_id","XXXX");//子商户号 //$refund->setParameter("device_info","XXXX");//设备号 //$refund->setParameter("transaction_id","XXXX");//微信订单号 //调用结果 $refundResult = $refund->getResult(); $sql = "insert into " . $GLOBALS['hhs']->table("refund_log") . " (order_sn,out_refund_no,refund_fee,transaction_id,status,note)" . " values ('{$order_sn}','{$out_refund_no}','{$refund_fee}','{$refundResult['transaction_id']}',0,'" . serialize($refundResult) . "' )"; $GLOBALS['db']->query($sql); //商户根据实际情况设置相应的处理流程,此处仅作举例 if ($refundResult["return_code"] == "FAIL") { // echo "通信出错:".$refundResult['return_msg']."<br>"; return false; } else { if ($refundResult['result_code'] == 'SUCCESS') { return true; } /* echo "业务结果:".$refundResult['result_code']."<br>"; echo "错误代码:".$refundResult['err_code']."<br>"; echo "错误代码描述:".$refundResult['err_code_des']."<br>"; echo "公众账号ID:".$refundResult['appid']."<br>"; echo "商户号:".$refundResult['mch_id']."<br>"; echo "子商户号:".$refundResult['sub_mch_id']."<br>"; echo "设备号:".$refundResult['device_info']."<br>"; echo "签名:".$refundResult['sign']."<br>"; echo "微信订单号:".$refundResult['transaction_id']."<br>"; echo "商户订单号:".$refundResult['out_trade_no']."<br>"; echo "商户退款单号:".$refundResult['out_refund_no']."<br>"; echo "微信退款单号:".$refundResult['refund_idrefund_id']."<br>"; echo "退款渠道:".$refundResult['refund_channel']."<br>"; echo "退款金额:".$refundResult['refund_fee']."<br>"; echo "现金券退款金额:".$refundResult['coupon_refund_fee']."<br>"; */ } }
/** * 申请退款 * $dataArr 提交参数内容 */ function WxRefundInterface($dataArr = array()) { $refund = new Refund_pub(); $refund->setParameter("transaction_id", $dataArr['transaction_id']); //微信订单号 $refund->setParameter("out_refund_no", $dataArr['out_refund_no']); //商户退款单号 $refund->setParameter("total_fee", $dataArr['total_fee']); //总金额 $refund->setParameter("refund_fee", $dataArr['refund_fee']); //退款金额 $refund->setParameter("op_user_id", WxPayConf_pub::MCHID); //操作员 //调用结果 $refundResult = $refund->getResult(); if ($refundResult["return_code"] == "FAIL") { echo "通信出错:" . $refundResult['return_msg'] . "<br>"; return false; } else { echo "业务结果:" . $refundResult['result_code'] . "<br>"; echo "签名:" . $refundResult['sign'] . "<br>"; if ($refundResult['result_code'] == "SUCCESS") { return true; } else { return false; } } }
public function refund() { if (empty($this->pay_config['pay_weixin_appid']) || empty($this->pay_config['pay_weixin_mchid']) || empty($this->pay_config['pay_weixin_key']) || empty($this->pay_config['pay_weixin_appsecret'])) { return array('error' => 1, 'msg' => '微信支付缺少配置信息!请联系管理员处理或选择其他支付方式。'); } $weixin_cert = C('config.pay_weixin_client_cert'); $weixin_key = C('config.pay_weixin_client_key'); if (empty($weixin_cert) || empty($weixin_key)) { return array('error' => 1, 'msg' => '管理员在后台支付配置中必须上传 微信支付证书和微信支付证书密钥!'); } import('@.ORG.pay.Weixinnewpay.WxPayPubHelper'); $refund = new Refund_pub($this->pay_config['pay_weixin_appid'], $this->pay_config['pay_weixin_mchid'], $this->pay_config['pay_weixin_key'], $this->pay_config['pay_weixin_appsecret']); $refund->setParameter("out_trade_no", $this->order_info['order_type'] . '_' . $this->order_info['order_id']); //商户订单号 $refund->setParameter("out_refund_no", $this->order_info['order_type'] . '_' . $this->order_info['order_id'] . '_' . $_SERVER['REQUEST_TIME']); //商户退款单号 $refund->setParameter("total_fee", $this->pay_money * 100); //总金额 $refund->setParameter("refund_fee", $this->pay_money * 100); //退款金额 $refund->setParameter("op_user_id", $this->pay_config['pay_weixin_mchid']); //操作员 $refundResult = $refund->getResult(); if ($refundResult['result_code'] == 'FAIL' && $refundResult['err_code'] != 'REFUND_FEE_INVALID') { $refund_param['err_msg'] = $refundResult['err_code_des']; $refund_param['refund_time'] = time(); return array('error' => 1, 'type' => 'fail', 'msg' => '退款申请失败!如果重试多次还是失败请联系系统管理员。', 'refund_param' => $refund_param); } else { $refund_param['refund_id'] = $refundResult['refund_id']; $refund_param['refund_time'] = time(); return array('error' => 0, 'type' => 'ok', 'msg' => '退款申请成功!请注意查收“微信支付”给您发的退款通知。', 'refund_param' => $refund_param); } }
$refund_fee = "1"; } else { $out_trade_no = $_POST["out_trade_no"]; $refund_fee = $_POST["refund_fee"]; //商户退款单号,商户自定义,此处仅作举例 $out_refund_no = "{$out_trade_no}" . "{$time_stamp}"; //总金额需与订单号out_trade_no对应,demo中的所有订单的总金额为1分 $total_fee = "1"; //使用退款接口 $refund = new Refund_pub(); //设置必填参数 //appid已填,商户无需重复填写 //mch_id已填,商户无需重复填写 //noncestr已填,商户无需重复填写 //sign已填,商户无需重复填写 $refund->setParameter("out_trade_no", "{$out_trade_no}"); //商户订单号 $refund->setParameter("out_refund_no", "{$out_refund_no}"); //商户退款单号 $refund->setParameter("total_fee", "{$total_fee}"); //总金额 $refund->setParameter("refund_fee", "{$refund_fee}"); //退款金额 $refund->setParameter("op_user_id", WxPayConf_pub::MCHID); //操作员 //非必填参数,商户可根据实际情况选填 //$refund->setParameter("sub_mch_id","XXXX");//子商户号 //$refund->setParameter("device_info","XXXX");//设备号 //$refund->setParameter("transaction_id","XXXX");//微信订单号 //调用结果 $refundResult = $refund->getResult();
public function refund($order) { $ret = new \stdClass(); $ret->haveNotify = false; $config = self::getConfig($order); if (!$config) { $ret->is_success = 'F'; $ret->error = "不存在的交易号:{$order['ser_recharge_no']}"; return $ret; } //使用退款接口 $refundObj = new \Refund_pub($config); $refundObj->setParameter("transaction_id", $order['ser_recharge_no']); //微信订单号 $refundObj->setParameter("out_refund_no", $order['mer_refund_no']); //商户退款单号 $refundObj->setParameter("total_fee", $order['recharge_amount']); //总金额 $refundObj->setParameter("refund_fee", $order['refund_amount']); //退款金额 $refundObj->setParameter("op_user_id", $config['partner']); //操作员 //$refundObj->setParameter("out_trade_no", 'xxxx') ; //商户订单号 //$refund->setParameter("sub_mch_id","XXXX") ; //子商户号 //$refund->setParameter("device_info","XXXX") ; //设备号 //调用结果 $refundResult = $refundObj->getResult(); if ($refundResult["return_code"] == "SUCCESS") { if ($refundResult['result_code'] == 'SUCCESS') { for ($i = 0; $i < 3; $i++) { sleep(1); $refundQueryResult = $this->refundQuery($order); if ($refundQueryResult->is_success == 'T' && $refundQueryResult->code == 1) { $notice = ['type' => 'refund', 'mer_refund_no' => $order['mer_refund_no'], 'ser_refund_no' => $order['ser_refund_no'], 'notify_status' => 2, 'notify_log' => 'SUCCESS', 'notify_time' => time(), 'refund_time' => time()]; SerNotifyBiz::getInstance()->payNotify($notice, 'refund'); break; } } } else { $ret->is_success = 'F'; $ret->code = 998; $ret->error = '提交业务失败:retmsg=' . $refundResult['err_code_des']; } } else { $ret->is_success = 'F'; $ret->code = 999; $ret->exception = true; $ret->error = '通信失败:retmsg=' . $refundResult['err_code_des']; } return $ret; }
/** * 支付逻辑 * $data array 传入数据 array("orderSn"=>"","money"=>"","attach"=>"") */ public function wechatRefund($data) { /** * JS_API支付demo * ==================================================== * 在微信浏览器里面打开H5网页中执行JS调起支付。接口输入输出数据格式为JSON。 * 成功调起支付需要三个步骤: * 步骤1:网页授权获取用户openid * 步骤2:使用统一支付接口,获取prepay_id * 步骤3:使用jsapi调起支付 */ //include_once("../WxPayPubHelper/WxPayPubHelper.php"); //使用jsapi接口 //$jsApi = new \System\lib\WxPay\JsApi_pub(); //=========步骤1:网页授权获取用户openid============ //通过code获得openid //$openid=$_SESSION['openid']; //echo $openid; //=========步骤2:使用统一支付接口,获取prepay_id============ //使用统一支付接口 //$unifiedOrder = new \System\lib\WxPay\UnifiedOrder_pub(); $this->vendor('WxPay.JsApi_pub'); $refund = new \Refund_pub(); //$refund = new \System\lib\WxPay\Refund_pub(); // if(empty($data['notifyUrl'])) { // $data['notifyUrl']= \System\lib\WxPay\WxPayConf_pub::NOTIFY_URL() ; // } //设置统一支付接口参数 //设置必填参数 //appid已填,商户无需重复填写 //mch_id已填,商户无需重复填写 //noncestr已填,商户无需重复填写 //spbill_create_ip已填,商户无需重复填写 //sign已填,商户无需重复填写 $refund->setParameter("out_trade_no", $data["out_trade_no"]); //商户订单号 $refund->setParameter("out_refund_no", $data["out_refund_no"]); //商户退款单号 $refund->setParameter("total_fee", $data["total_fee"]); //总金额 $refund->setParameter("refund_fee", $data["refund_fee"]); //总金额 $refund->setParameter("op_user_id", $data["op_user_id"]); //操作员帐号, 默认为商户号 //$refund->setParameter("mch_id","XXXX");//商户号 //$refund->setParameter("appid","XXXX");//商户号 //$refund->setParameter("openid","$openid");//商品描述 //$refund->setParameter("body",$data['body']);//商品描述 //$refund->setParameter("detail",$data['detail']);//商品描述 //自定义订单号,此处仅作举例 // $timeStamp = time(); // $out_trade_no = \System\lib\WxPay\WxPayConf_pub::APPID()."$timeStamp"; // $refund->setParameter("notify_url", $data['notifyUrl']);//通知地址 // //$unifiedOrder->setParameter("notify_url", $data['notifyUrl']);//通知地址 // $refund->setParameter("trade_type","JSAPI");//交易类型 // //非必填参数,商户可根据实际情况选填 // //$unifiedOrder->setParameter("device_info","XXXX");//设备号 // $refund->setParameter("attach",$data['attach']);//附加数据 // //$unifiedOrder->setParameter("time_start","XXXX");//交易起始时间 // //$unifiedOrder->setParameter("time_expire","XXXX");//交易结束时间 // //$unifiedOrder->setParameter("goods_tag",$data['goods_tag']);//商品标记 // //$unifiedOrder->setParameter("openid","XXXX");//用户标识 // //$unifiedOrder->setParameter("product_id",$data['product_id']);//商品ID // $prepay_id = $refund->getPrepayId(); // //dump($unifiedOrder->createXml()); // //dump($prepay_id); // //exit(); // if(!$prepay_id) return false; // //=========步骤3:使用jsapi调起支付============ // $jsApi->setPrepayId($prepay_id); // $jsApiParameters = $jsApi->getParameters(); // //dump($jsApiParameters); // dump($refund); $result = $refund->postXml(); dump($result); return $result; }
/** * 申请退款 * $dataArr 提交参数内容 */ function WxRefundInterface($dataArr = array()) { $refund = new Refund_pub(); //$refund->setParameter("transaction_id", $dataArr['transaction_id']); //微信订单号 $refund->setParameter("out_trade_no", $dataArr['out_trade_no']); //微信订单号 $refund->setParameter("out_refund_no", $dataArr['out_refund_no']); //商户退款单号 $refund->setParameter("total_fee", $dataArr['total_fee']); //总金额 $refund->setParameter("refund_fee", intval($dataArr['refund_fee'])); //退款金额 $refund->setParameter("op_user_id", WxPayConf_pub::MCHID); //操作员 //调用结果 $refundResult = $refund->getResult(); if ($refundResult["return_code"] == "FAIL") { echo "通信出错:" . $refundResult['return_msg'] . "<br>"; return false; } else { echo "业务结果:" . $refundResult['result_code'] . "<br>"; echo "错误代码:" . $refundResult['err_code'] . "<br>"; echo "错误代码描述:" . $refundResult['err_code_des'] . "<br>"; echo "公众账号ID:" . $refundResult['appid'] . "<br>"; echo "商户号:" . $refundResult['mch_id'] . "<br>"; echo "子商户号:" . $refundResult['sub_mch_id'] . "<br>"; echo "设备号:" . $refundResult['device_info'] . "<br>"; echo "签名:" . $refundResult['sign'] . "<br>"; echo "微信订单号:" . $refundResult['transaction_id'] . "<br>"; echo "商户订单号:" . $refundResult['out_trade_no'] . "<br>"; echo "商户退款单号:" . $refundResult['out_refund_no'] . "<br>"; echo "微信退款单号:" . $refundResult['refund_idrefund_id'] . "<br>"; echo "退款渠道:" . $refundResult['refund_channel'] . "<br>"; echo "退款金额:" . $refundResult['refund_fee'] . "<br>"; echo "现金券退款金额:" . $refundResult['coupon_refund_fee'] . "<br>"; if ($refundResult['return_code'] == "SUCCESS") { return true; } else { return false; } } }