wxpayNotify微信支付回调函数 * * * * * >[success]微信支付回调地址填写域名即可,支付后本函数是自动执行,订单交易成功并且订单是有效的,会自动处理金额入库。 ~~~ /** * 微信支付回调 * @return bool */ function wxpayNotify() { if ($xml = file_get_contents('php://input')) { $xml_parser = xml_parser_create(); if (!xml_parse($xml_parser, $xml, true)) { xml_parser_free($xml_parser); return false; } else { $array = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true); if (isset($array['out_trade_no']) && isset($array['openid']) && isset($array['mch_id']) ) { $paymentModel = new \app\common\model\Payment(); if (!$payment = $paymentModel->getPaymentByFind(['order_number' => $array['out_trade_no']])) { $data = ['return_code' => 'FAIL', 'return_msg' => '定单号不存在']; } else { try { setWxpayConfig($payment['mpid']); \WxPayResults::Init($xml); $result = queryOrder($array['out_trade_no']); if ($result['errCode'] == 'ok') { $data = ['return_code' => 'SUCCESS', 'return_msg' => 'OK']; } else { $data = ['return_code' => 'FAIL', 'return_msg' => $result['errMsg']]; } } catch (\Exception $exception) { $data = ['return_code' => 'FAIL', 'return_msg' => $exception->getMessage()]; } } echo array_to_xml($data); } } } } ~~~