public function refundxxx()
{
$postStr = file_get_contents("php://input");
file_put_contents('refund_notify.log', date('Y-m-d H:i:s') . $postStr . PHP_EOL, FILE_APPEND);
$postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
if ($postObj === false) {
WxapayService::notifySuccess();
}
$postObj = (array)$postObj;
if ($postObj['return_code'] != 'SUCCESS' || $postObj['return_msg'] != 'OK') {
WxapayService::notifySuccess();
}
$req_info = $postObj['req_info'];
$appId = $postObj['appid'];
$mch_id = $postObj['mch_id'];
$wxappSettings = db('wxapp')->where('app_id', $appId)->where('mch_id', $mch_id)->find();
if (empty($wxappSettings)) {
WxapayService::notifySuccess();
}
$req_info_xml = openssl_decrypt(base64_decode($req_info), 'aes-256-ecb', md5($wxappSettings['api_key']), OPENSSL_RAW_DATA);
$req_info_arr = simplexml_load_string($req_info_xml, 'SimpleXMLElement', LIBXML_NOCDATA);
if ($req_info_arr === false) {
WxapayService::notifySuccess();
}
$req_info_arr = (array)$req_info_arr;
$out_trade_no = $req_info_arr['out_trade_no'];
$order = Db::name('vip_charge_log')->where('order_sn', $out_trade_no)->find();
if (empty($order) || $order['refund_status'] == 1) {
WxapayService::notifySuccess();
}
if ($req_info_arr['refund_status'] == 'SUCCESS') {
write_log("退款成功,退款返回信息:" . json_encode($req_info_arr) . ",执行操作时间:" . date('Y-m-d H:i:s', time()), 'wxpay_refund_success');
$res = Db::name('vip_charge_log')->where('id', $order['id'])->update([
'refund_id' => $req_info_arr['out_refund_no'],
'refund_status' => 1,
]);
} else {
ChargeService::refundBalance($order['id']);
}
WxapayService::notifySuccess();
}
public static function notifySuccess()
{
echo '<xml>
<return_code><![CDATA[SUCCESS]]></return_code>
<return_msg><![CDATA[OK]]></return_msg>
</xml>';
exit;
}
public static function notifyFail()
{
echo '<xml>
<return_code><![CDATA[FAIL]]></return_code>
<return_msg><![CDATA[FAIL]]></return_msg>
</xml>';
exit;
}