2019-03-26 13:39:36 1124瀏覽
今天扣丁學(xué)堂PHP培訓(xùn)老師給大家介紹一下關(guān)于PHP微信支付功能的詳細(xì)介紹,并結(jié)合實例形式分析了php微信支付功能相關(guān)sdk與使用技巧。
import("wxpay.lib.AppPay#Config", EXTEND_PATH, ".php"); import("wxpay.lib.WxPay#Api", EXTEND_PATH, ".php"); //$this->weixinpay(); $config = new \AppPayConfig(); //訂單號 $appId = $config->GetAppId(); $key = $config->GetKey(); $money = 0.01 * 100; $orderSn = 'M201810241754107557';//訂單號; $curTime = time(); $input = new \WxPayUnifiedOrder(); $input->SetBody("用戶紅包"); $input->SetOut_trade_no($orderSn); $input->SetTotal_fee($money); $input->SetTrade_type("APP"); $unifiedOrder = \WxPayApi::unifiedOrder($config, $input); if ($unifiedOrder['result_code'] == 'SUCCESS' && $unifiedOrder['return_code'] == 'SUCCESS') { /*$unifiedOrder 組成: * ["appid"] => string(18) "wx2xxxx49" ["mch_id"] => string(10) "1xxxxxx01" ["nonce_str"] => string(16) "1GnEUXTuTcFtJVtb" ["prepay_id"] => string(36) "wx241933xxx68fa24ece70611692955" ["result_code"] => string(7) "SUCCESS" ["return_code"] => string(7) "SUCCESS" ["return_msg"] => string(2) "OK" ["sign"] => string(32) "7903xxxxx4710E460CB156" ["trade_type"] => string(3) "APP"*/ $curTime = time(); // 第一部分 $wxpayResult = new \WxPayResults(); $wxpayResult->SetData('appid', $unifiedOrder['appid']); $wxpayResult->SetData('partnerid', $unifiedOrder['mch_id']); $wxpayResult->SetData('prepayid', $unifiedOrder['prepay_id']); $wxpayResult->SetData('noncestr', $unifiedOrder['nonce_str']); $wxpayResult->SetData('timestamp',$curTime); $wxpayResult->SetData('package',"Sign=WXPay"); $wxpayResult->SetData('sign',""); $wxpayResult->SetSign($config); $data = $wxpayResult->GetValues(); // 第二部分 $data['appid'] = $unifiedOrder['appid']; $data['partnerid'] = $unifiedOrder['mch_id']; $data['prepayid'] = $unifiedOrder['prepay_id']; $data['noncestr'] = $unifiedOrder['nonce_str'];; $data['timestamp'] = $curTime; $data['package'] = "Sign=WXPay"; $data['sign'] = $this->wxappPaySign($key, $data);//$unifiedOrder['sign'];//簽名,具體簽名方案參見微信公眾號支付幫助文檔; $this->returnSuccess($data); } else { Log::write(var_export($unifiedOrder, true)); $this->returnError(300, '微信支付失敗'); } private function wxappPaySign($key,$parameters) { $sign = md5(sprintf("appid=%s&noncestr=%s&package=%s&partnerid=%s&prepayid=%s×tamp=%s&key=%s", $parameters['appid'], $parameters['noncestr'], $parameters['package'], $parameters['partnerid'], $parameters['prepayid'], $parameters['timestamp'], $key)); return strtoupper($sign); }
想要了解更多關(guān)于PHP開發(fā)方面內(nèi)容的小伙伴,請關(guān)注扣丁學(xué)堂PHP培訓(xùn)官網(wǎng)、微信等平臺,扣丁學(xué)堂IT職業(yè)在線學(xué)習(xí)教育有專業(yè)的PHP講師為您指導(dǎo),此外扣丁學(xué)堂老師精心推出的PHP視頻教程定能讓你快速掌握PHP從入門到精通開發(fā)實戰(zhàn)技能??鄱W(xué)堂PHP技術(shù)交流群:374332265。
【關(guān)注微信公眾號獲取更多學(xué)習(xí)資料】 【掃碼進(jìn)入HTML5進(jìn)階免費公開課】
查看更多關(guān)于“php培訓(xùn)資訊”的相關(guān)文章>>