您好,登錄后才能下訂單哦!
這篇文章給大家介紹如何是PHP實現(xiàn)微信支付功能,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。
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); }
php是一個嵌套的縮寫名稱,是英文超級文本預(yù)處理語言,它的語法混合了C、Java、Perl以及php自創(chuàng)新的語法,主要用來做網(wǎng)站開發(fā),許多小型網(wǎng)站都用php開發(fā),因為php是開源的,從而使得php經(jīng)久不衰。
關(guān)于如何是PHP實現(xiàn)微信支付功能就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。