/** * 微信支付异步回调API * 微信支付成功,会收到异步回调 */ public function actionWxpay() { $weixinPay = new WeixinPay(); $weixin = new Weixin(); $xml = file_get_contents('php://input'); $msg = $weixin->parseMsg($xml); //记录微信推送日志 $notifyMongo = new WeixinPayNotify(); $notifyMongo->logPayNotify($xml); if (!$msg || !is_object($msg)) { $weixinPay->notifyXml('FAIL', '通知不合法'); } if (!isset($msg->return_code) || $msg->return_code != 'SUCCESS') { $weixinPay->notifyXml('FAIL', '通信失败'); } if (!isset($msg->result_code) || $msg->result_code != "SUCCESS") { $weixinPay->notifyXml('FAIL', '交易失败'); } //签名验证失败 if (!$weixinPay->checkSign($msg)) { $weixinPay->notifyXml('FAIL', '签名验证失败'); } //$notifyMongo->add($msg); //流程走到这里说明已经支付成功了,这里无需更新订单逻辑 $userOrder = new UserOrder(); //记录微信订单号 $userOrder->pay($msg->out_trade_no, $msg->transaction_id); }
/** * 利用统一支付接口获取预支付订单id */ public function getPrepayId() { $url = 'https://api.mch.weixin.qq.com/pay/unifiedorder'; $this->bodyArr(); $wx = new Weixin(); $xml = $this->arrayToXml(); $msg = $wx->rawpost($url, $xml); $msgArr = $wx->parseMsg($msg); if (!$msgArr || !is_object($msgArr)) { throw new \Exception('预支付订单申请请求失败'); } //print_r($msgArr);exit(); if ($msgArr->return_code == 'SUCCESS') { $this->param['prepay_id'] = $msgArr->prepay_id; } else { throw new \Exception('无法创建预支付订单'); } }
/** * 获取二维码原始信息 * token = md5(id+inner_weixin_key+id) * @param $scene * @param $token */ public function actionGetqrcode() { $params = $this->getParams(); //解析字符串 $scene = $params['scene']; $token = $params['token']; $innerWeixinKey = WEIXIN_INNER_KEY; $trueToken = md5($scene . $innerWeixinKey . $scene); if ($token != $trueToken) { $this->innerOutput(1, '无法通过请求认证'); } $accessMongo = new WeixinAccessToken(); $access_token = $accessMongo->getAccessToken(); if (!$access_token) { $this->innerOutput(2, '无法获取access_token'); } $weixin = new Weixin(); $qrdata = $weixin->getQrticket($access_token, $scene); if (!$qrdata || !is_array($qrdata)) { $this->innerOutput(3, '无法获取二维码信息'); } $this->innerOutput(0, '成功获取二维码信息', $qrdata); }