第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

求幫忙小程序支付 appid and openid not match 如何怎么解決?

求幫忙小程序支付 appid and openid not match 如何怎么解決?

PHP
qq_巴黎小鎮(zhèn)_03532497 2018-06-01 17:57:28
以下是代碼namespace app\api\service;use app\api\model\Order as OrderModel;use app\lib\enum\OrderStatusEnum;use app\lib\exception\OrderException;use app\lib\exception\TokenException;use think\Exception;use think\Loader;use think\Log;Loader::import('WxPay.WxPay', EXTEND_PATH, '.Api.php');class Pay{? ? private orderID;? ? function __construct($orderID)? ? {? ? ? ? if (!$orderID)? ? ? ? {? ? ? ? ? ? throw new Exception('訂單號不允許為NULL');? ? ? ? }? ? ? ? orderID;? ? }? ? public function pay()? ? {? ? ? ? $this->checkOrderValid();? ? ? ? $order = new Order(); ? ? ? //這里是service的 Order? ? ? ? order->checkOrderStock($this->orderID);? ? ? ? if (!$status['pass'])? ? ? ? {? ? ? ? ? ? return $status;? ? ? ? }? ? ? ? return $this->makeWxPreOrder($status['orderPrice']);? ? }? ? // 構(gòu)建微信支付訂單信息? ? private function makeWxPreOrder($totalPrice)? ? {? ? ? ? $openid = Token::getCurrentTokenVar('openid');? ? ? ? if (!$openid)? ? ? ? {? ? ? ? ? ? throw new TokenException();? ? ? ? }? ? ? ? $wxOrderData = new \WxPayUnifiedOrder();? ? ? ? $wxOrderData->SetOut_trade_no($this->orderNo); ? //訂單號? ? ? ? $wxOrderData->SetTrade_type('JSAPI'); ? ? ? ? ? ?//交易類型? ? ? ? $wxOrderData->SetTotal_fee($totalPrice * 100); ? //金額? ? ? ? $wxOrderData->SetBody('測試'); ? ? ? ? ? ? ? //設(shè)置商品或支付單簡要描述? ? ? ? $wxOrderData->SetOpenid($openid); ? ? ? ? ? ? ? ?//用戶的openid? ? ? ? $wxOrderData->SetNotify_url(config('secure.pay_back_url')); ?//設(shè)置接收微信支付異步通知回調(diào)地址? ? ? ? return $this->getPaySignature($wxOrderData);? ? }? ? //向微信請求訂單號并生成簽名? ? /**? ? ?* @param $wxOrderData? ? ?* @return array? ? ?*/? ? private function getPaySignature($wxOrderData)? ? {? ? ? ? $wxOrder = \WxPayApi::unifiedOrder($wxOrderData);? ? ? ?返回結(jié)果appid and openid not match? ? ? ? // 失敗時不會返回result_code? ? ? ? if($wxOrder['return_code'] != 'SUCCESS' || $wxOrder['result_code'] !='SUCCESS'){? ? ? ? ? ? //dump($wxOrder);? ? ? ? ? ? Log::record($wxOrder,'error');? ? ? ? ? ? Log::record('獲取預(yù)支付訂單失敗','error');? ? ? ? ? ? //throw new Exception('獲取預(yù)支付訂單失敗');? ? ? ? }? ? ? ? $this->recordPreOrder($wxOrder);? ? ? ? this->sign($wxOrder);? ? ? ? return $signature;? ? }? ? private function recordPreOrder($wxOrder){? ? ? ? // 必須是update,每次用戶取消支付后再次對同一訂單支付,prepay_id是不同的? ? ? ? OrderModel::where('id', '=', $this->orderID)? ? ? ? ? ? ->update(['prepay_id' => $wxOrder['prepay_id']]);? ? }? ? // 簽名? ? private function sign($wxOrder)? ? {? ? ? ? $jsApiPayData = new \WxPayJsApiPay();? ? ? ? $jsApiPayData->SetAppid(config('wx.app_id'));? ? ? ? $jsApiPayData->SetTimeStamp((string)time());? ? ? ? $rand = md5(time() . mt_rand(0, 1000));? ? ? ? $jsApiPayData->SetNonceStr($rand);? ? ? ? $jsApiPayData->SetPackage('prepay_id=' . $wxOrder['prepay_id']);? ? ? ? $jsApiPayData->SetSignType('md5');? ? ? ? jsApiPayData->MakeSign();? ? ? ? jsApiPayData->GetValues(); ? ?//數(shù)組? ? ? ? sign;? ? ? ? unset($rawValues['appId']);? ? ? ? return $rawValues;? ? }? ? /**? ? ?* @return bool? ? ?* @throws OrderException? ? ?* @throws TokenException? ? ?*/? ? private function checkOrderValid()? ? {? ? ? ? $order = OrderModel::where('id', '=', $this->orderID)? ? ? ? ? ? ->find();? ? ? ? if (!$order)? ? ? ? {? ? ? ? ? ? throw new OrderException();? ? ? ? }// ? ? ? ?$currentUid = Token::getCurrentUid();? ? ? ? if(!Token::isValidOperate($order->user_id))? ? ? ? {? ? ? ? ? ? throw new TokenException(? ? ? ? ? ? ? ? [? ? ? ? ? ? ? ? ? ? 'msg' => '訂單與用戶不匹配',? ? ? ? ? ? ? ? ? ? 'errorCode' => 10003? ? ? ? ? ? ? ? ]);? ? ? ? }? ? ? ? if($order->status != OrderStatusEnum::UNPAID){? ? ? ? ? ? throw new OrderException([? ? ? ? ? ? ? ? 'msg' => '訂單已支付過啦',? ? ? ? ? ? ? ? ?'errorCode' => 80003,? ? ? ? ? ? ? ? 'code' => 400? ? ? ? ? ? ]);? ? ? ? }? ? ? ? order->order_no;? ? ? ? return true;? ? }}
查看完整描述

目前暫無任何回答

  • 0 回答
  • 0 關(guān)注
  • 3051 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號