欧美成人午夜免费全部完,亚洲午夜福利精品久久,а√最新版在线天堂,另类亚洲综合区图片小说区,亚洲欧美日韩精品色xxx

扣丁學(xué)堂PHP培訓(xùn)之微信支付功能示例詳解

2019-03-26 13:39:36 1124瀏覽

今天扣丁學(xué)堂PHP培訓(xùn)老師給大家介紹一下關(guān)于PHP微信支付功能的詳細(xì)介紹,并結(jié)合實例形式分析了php微信支付功能相關(guān)sdk與使用技巧。



微信開發(fā)SDK:文中用的是php_sdk_v3.0.9:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=11_1

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)于扣丁學(xué)堂PHP培訓(xùn)之微信支付功能示例的詳細(xì)介紹,

想要了解更多關(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)文章>>

標(biāo)簽: PHP培訓(xùn) PHP視頻教程 PHP在線視頻 PHP學(xué)習(xí)視頻

熱門專區(qū)

暫無熱門資訊

課程推薦

微信
微博
15311698296

全國免費咨詢熱線

郵箱:codingke@1000phone.com

官方群:148715490

北京千鋒互聯(lián)科技有限公司版權(quán)所有   北京市海淀區(qū)寶盛北里西區(qū)28號中關(guān)村智誠科創(chuàng)大廈4層
京ICP備2021002079號-2   Copyright ? 2017 - 2022
返回頂部 返回頂部