搜尋
首頁後端開發php教程PHP實作微信支付功能開發程式碼分享

PHP實作微信支付功能開發程式碼分享

Mar 09, 2018 pm 04:53 PM
php程式碼開發

本文主要和大家詳細介紹了PHP微信支付開發過程,具有一定的參考價值,有興趣的小夥伴們可以參考一下,希望能幫助到大家。

1.開發環境 
Thinkphp 3.2.3 
微信:服務編號,已認證 
開發網域:http://test.paywechat.com (自定義的域名,外網不可訪問)

2.需要相關文件和權限 
微信支付需申請開通 
微信公眾平台開發者文件:http:// mp.weixin.qq.com/wiki/home/index.html 
微信支付開發者文件:https://pay.weixin.qq.com/wiki/doc/api/index.html 
#微信支付SDK下載網址:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=11_1

3.開發 
#下載好微信支付PHP版本的SDK,檔案目錄為下圖:

PHP實作微信支付功能開發程式碼分享

PHP實作微信支付功能開發程式碼分享

把微信支付SDK的Cert和Lib目錄放入Thinkphp,目錄為 

PHP實作微信支付功能開發程式碼分享 

現在介紹微信支付授權目錄問題,首先是微信支付開發配置裡面的支付授權目錄填寫, 

PHP實作微信支付功能開發程式碼分享

然後填入js介面安全域。

PHP實作微信支付功能開發程式碼分享

最後設定網頁授權 

#

PHP實作微信支付功能開發程式碼分享

PHP實作微信支付功能開發程式碼分享

這些設定完,基本上完成一半,注意設定的目錄和我thinkphp裡面的目錄。 

PHP實作微信支付功能開發程式碼分享

4.微信支付配置

PHP實作微信支付功能開發程式碼分享

##把相關設定填入正確。




#[php] view plain copy


  1. /**  

  2. * 設定帳號資訊 

  3. */  

  4. #  

  5. class WxPayConfig  

  6. ##{  

  7. //=======【基本資訊設定】====================== =================  

  8. //  

  9.  /** 

  10.  * TODO: 修改這裡設定為您自己申請的商家資訊 

  11.  * 微信公號資訊設定 

  12.  *  

  13. ## * APPID :綁定付款的APPID(必須配置,開戶郵件中可檢視) 

  14.  *  

  15. # * MCHID:商家號碼(必須配置,開戶郵件中可檢視) 

  16.  *  

  17. # * KEY:商家支付金鑰,參考開戶郵件設定(必須配置,登入商家平台自行設定) 

  18.  * 設定位址:https://pay.weixin.qq.com/index.php/account/api_cert 

  19.  *  

  20. ## * APPSECRET:公用帳號secert(只有JSAPI付款的時候需要配置, 登入公眾平台,進入開發者中心可設定),

     #

  21.  * 取得網址:https://mp.weixin.qq.com/advanced/advanced?action=dev&t=advanced/dev&token=2005451881&lang=zh_CN 

  22.  * @var string 

  23.  */   

  24. const APPID = ''

  25. ;  
  26.  const MCHID = ##''

  27. ;  
  28.  const KEY = ''

  29. ;
  30.  const# APPSECRET = ''

  31. #;  
  32.   

    //=======【憑證路徑設定】=====================================

  33.   
  34.  
  35. /**

     

  36.  * TODO :設定商家憑證路徑

     

    ####### * 憑證路徑,注意應該填寫絕對路徑(僅退款、撤銷訂單時需要,可登入商家平台下載,### #######
  37.  * API憑證下載位址:https://pay.weixin.qq.com/index.php/account/api_cert,下載前需安裝商家操作憑證) 

  38.  * @var path 

  39.  */  

  40. const

     SSLCERT_PATH = 

    #'. ./cert/apiclient_cert.pem'
  41. ;  

     

    const
  42.  SSLKEY_PATH = 

    const SSLKEY_PATH =  #'../cert/apiclient_key.pem'

  43. ;  
  44.   
  45. //=======【curl代理設定】========================= ============

  46.   
  47. /**
  48.  

  49.  * TODO:這裡設定代理機器,只有需要代理的時候才設置,不需要代理,請設定為0.0.0.0和0
  50.  

     * 本程式透過curl使用HTTP POST方法,此處可修改代理伺服器,

     ### ################## * 預設CURL_PROXY_HOST=0.0.0.0和CURL_PROXY_PORT=0,此時不開啟代理程式(若有需要才設定)### ##### ################ * @var unknown_type### ##################### */ ######  #########
  51.  const CURL_PROXY_HOST = "0.0.0.0";#// "10.152.18.220";  

  52.  const# CURL_PROXY_PORT = 0;# CURL_PROXY_PORT = 0; //8080;

      
  53. #  
  54. ## 
  55. //=======【回報資訊配置】================================= ====

      

  56. /** 

  57.  * TODO:介面呼叫上報等級,預設緊錯誤上報(註:上報超時間為【1s】,上報無論成敗【永不拋出例外】, 

  58. # * 不會影響介面呼叫流程),開啟回報之後,方便微信監控請求調用的質量,建議至少 

  59. # * 開啟錯誤回報。  

  60.  * 回報等級,0.關閉回報; 1.僅錯誤回報; 2.全量回報

     

    # * @var int
  61.  
  62. ###### */######  ################################/#######################################################################################################。 ################### ###const####### REPORT_LEVENL = 1;  ####################################################################### ####}  #######

現在開始貼出程式碼:




#[php] view plain copy


  1. namespace Wechat\ Controller;  

  2. #use Think\Controller;  

  3. /** 

  4.  * 父類別控制器,需繼承 

  5. # * @file ParentController.class.php

     

     * @author Gary  ### ##################### * @date 2015年8月4日### ############### ####### * @todu### ###################### */#######  #########
  6. class ParentController extends Controller {   

  7.  Controller {      protected 

  8. #$options
  9.  = array# (  ##array# (  

  10.  
  11. 'token'

    # => ''// 填寫你設定的key  

  12. 'encodingaeskey'

     => ''#// 填入加密使用的EncodingAESKey  

  13. 'appid'

     => ''// 填寫高級呼叫功能的app id  

    #### ###'appsecret'###### => #### ###''######, ######// 填入進階呼叫功能的金鑰######  #########
  14. '偵錯'# => false,

  15. 'logcallback'# => ''  

  16. );   

  17. ##public#$errCode=40001;   

  18. #public#$errMsg==「無法存取」;   

  19. #/** 

  20. ## * 取得access_token

     

  21. * @return mixed|boolean|unknown

     

  22. # */

      

  23. #公用

     #函數

    ############################################################################################################################。 getToken(){  ##########
  24. ##$cache_token=S('exp_wechat_pay_token');  

  25. if(!空白##( $cache_token)){  

  26. ##return

      # $cache_token;  

    ## }  
  27. ##$url
  28. # = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s';  #$url=sprintf($url,

    $this######->選項[######'appid'#######],######$this##### ->選項[######'appsecret'######]);   ##########
  29.  $結果 = $this->http_get($網址);  

  30. #$結果 = json_decode($結果,真的);   

  31. if(##(## ) ##$結果)){  

  32. #回傳

    # false;  

    ## }   
  33. S(
  34. 'exp_wechat_pay_token'
  35. ,$結果['access_token'],陣列 ( '類型'=>'檔案',##'過期'# => 3600));  #

  36.  #return #$結果['access_token' ];  

  37.  }  

  38. ## #########/**&# #民眾 函數 sendCustomMessage($data){  

  39. ## #$token = $this->getToken();  

  40. ##if$token)) return false;   #

  41.  $url = 'https://api.weixin.qq.com/cgi-bin/message/custom /send?access_token=%s';  

  42. #$url=sprintf($url, $令牌);  

  43. ## 

    $結果# = $this-> http_post( $url,self::json_encode($data));  

  44. if$  {  

  45. #$json
  46.  = json_decode (

    $結果,true);  #

  47.  #if (!$ ##($json['錯誤代碼'])) {  

  48.  $this->errCode = $json[#'errcode ' ];  

  49. #$this->errMsg = $json

  50. [
  51. 'errmsg'];  

  52. #return false;  ################ $json;  ################錯誤的;  

  53.  }  

  54.   

  55. ########################################
  56. #/** 

  57.  * 傳送範本訊息 

  58.  * @param unknown $data 

  59.  * @return boolean|unknown 

  60.  */

  61. ##public function sendTemplateMessage($data){  

  62. $token = $this->getToken();  

  63. ##if$token)) return false;  

  64. ## 

    $url# = "https://api.weixin.qq. com /cgi-bin/message/template/send?access_token=%s"#;  #

  65.  $url = sprintf($url,$token);  

  66.  $result = $this->http_post($url,self::json_encode($data));  

  67.  if ($result)  

  68.  {  

  69.  $json = json_decode($result,true);  

  70.  #if (!$ ##($json['錯誤代碼'])) {  

  71.  $this->errCode = $json[#'errcode ' ];  

  72. #$this->errMsg = $json

  73. [
  74. 'errmsg'];  

  75. #return false;  ################ $json;  ################錯誤的;  

  76.  }  

  77.   

  78. ########################################
  79.   

  80.  public function getFileCache($name){  

  81. return S($name);  

  82.  }  

  83. ## #########/**&# #靜止的 函數 json_encode($arr) {  

  84. ## 

    #$零件 = 陣列 ();  

    #####################$is_list####### = false;  ########################//判斷給定的陣列是否為數值陣列############## #
  85.  #$keys = array_keys ( #$arr#);  

  86. ##$max_lengthcount#$arr ) - 1;  

  87. #if(($keys##[0] == = 0) && ($keys [$max_length] === #$max_length )) { //檢視第一個鍵是否為0,最後一個鍵的長度是否為-1  

  88.  
  89. #$is_list

     = true;  #

  90. #for($i= 0; $i count ( #$keys );  $i ++) { //檢視每個按鍵是否對應其位置  

  91. if ($i

     != 
  92. $keys

     [

    $i
  93. ]) { 

    //某個按鍵在位置檢查時失敗。 ##  $is_list

  94. = false; 
  95. //這是一個關聯陣列。 # #;  

    ############ }  ################## }  #################################################################### # ######### }  ########
  96.  #foreach ( $arr as

  97. $key

  98.  => 
  99. $value ) {  

  100. ## 
  101. #if

     (is_array ( $value )) { #//陣列的自訂處理  

  102. if (

    # ##$is_list######)  ##########################$parts###### [ ] = self::json_encode (######$值######); ######/* :遞歸: */#######  ##########################else#### ## #########
  103.   $零件 [] = '"' . $key  .  '":' . self::json_encode ($value); /* :遞迴: */  

  104. # } #else {  

  105. $str = ##''

    ##;  
  106. if(!$is_list

    )  
  107. #  $str# = '"' .  $key .  '":'

    #;  
  108. //多種資料類型的自訂處理

    #########
  109. if (!is_string$value# ) && is_numeric ( $value ) && $value$value

  110. ##  $str .= $value//數字

      
  111. ## elseif ( $value

     === false)  
  112. $str# . = ######'錯誤的'######; //布林值  

  113.  elseif ( ##$value === true)

  114. #$str##'true';  #

  115.  #else  

  116. #  $str  .= '"' . 新增斜線## ( #$value ) .  '"'//所有其​​他事情  

  117. #//:TODO:還有嗎我們該留意的資料類型? (對象?)  

  118. $parts [] = $str;  

  119.  }  

  120.  }  

  121. ## #$json = 內爆 ( ','#$parts

    ### );  ########################if######(######$is_list######)  ############################################# ######
  122.  return #'[' . $json . ']'##; //Return numerical JSON#  

  123. ## return '{' . $json . '}'//Return associative JSON  

  124. # }  

  125.   

  126.  
  127. /**

     

  128.  +------------------------------ ----------------------------

     

    ##### ## * 產生隨機字串### ###################### +------------------ ------------------------------------------### ######## ############## * @param int $length 要產生的隨機字串長度### ##################### # * @param string $type 隨機碼類型:0,數字+大小寫字母;1,數字;2,小寫字母;3,大寫字母;4,特殊字元;-1,數字+大小寫字母+特殊字元# ## ######
  129. ## +----------------------------------- ------------------------------------- 

  130. # * @回傳字串

  131. +-------- ---------------- ---------------------------------- -

  132. ###### ##### ###靜止的##### $length
  133.  = 5, $類型# = 2){  

  134. # # $arr = 陣列(1 => 

    "0123456789"
  135. , 2 => 

    "abcdefghijklmnopqrstuvwxyz"##, 3 = > "ABCDEFGHIJKLMNOPQRSTUVWXYZ"#, 4 => " &*(){}[]|");  #if$type===0) { #

  136.  #array_pop($arr);  

  137. #$string#==內爆("", $arr);  

  138.  } #elseif ($type == ##"-1") {  

  139. $string

  140. # =內爆(""

  141. $arr
  142. );  ########### # #$string = $arr[$type##];  

  143.  }  #

  144.  $count = strlen($string#) - 1;  

  145. $程式碼#= '';  

  146. for$i##=0;$i $長度#; $i++) {  

  147. #$code.=$string[rand(0 , $count)];  ################ $程式碼;  

  148.  }   
  149.   

  150. ##  

    #####/******# ######
  151. ## * GET 請求

  152.  * @param string $url 

  153. ##*/  

  154. 問題# # private

  155.  
  156. function# http_get($url

    #function
  157. # http_get(

    $url){   ##$oCurl

  158. =curl_init();  
  159. #########if######(######stripos#####(#### ) ##$url######,######"https://"######)!==FALSE){  ############# # ###### curl_setopt(###$oCurl######, CURLOPT_SSL_VERIFYPEER, FALSE);  #####################curl_setopt(###$oCurl######, CURLOPT_SSL_VERIFYHOST, FALSE);  #####################curl_setopt(###$oCurl######, CURLOPT_SSLVERSION, 1); ######//CURL_SSLVERSION_TLSv1######  ###################### }  #######
  160. curl_setopt($oCurl#, CURLOPT_URL, $url);  

  161. curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1);  

  162. #$sContent#=curl_exec($oCurl) ;  

  163. #$aStatus#=curl_getinfo($oCurl) ;  

  164. ## curl_close(
  165. $oCurl

    #);  

  166. if

    (intval##(# ) ##$aStatus["http_code"])==200){  

    #return
  167.  

    $sContent;  ################# # #返回 假;  #

  168.  }  

  169. # }  

  170. ##/**

     
  171.  * POST 請求

     
  172. # # * @param string $url  * @param array $param 

  173.  * @param boolean $post_file 是否檔案上傳 

    ######### * @return string content# ## ###################### */##################### ## ###### ####private###### ######函數###### http_post(######$url#######,# ### ##$param######,######$post_file######=false){  ########################## #### ###$oCurl###### = curl_init();  ##########
  174.  #if(#stripos#($url,"https://")!==FALSE){  

  175. curl_setopt( $oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);  

  176. curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, false);  

  177. curl_setopt($oCurl, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1  

  178. # }  

  179. # }   ## #if (is_string($param) || 

    $post_file
  180. ) {  

    ##$strPOST# = 

    $參數
  181. ;  ###########
  182. ##$aPOST=陣列();  

  183. #foreach($param ## as $key=>#$val){  

    ## 
  184. $aPOST
  185. [] = $key##."= “ .urlencode($val);  ## }  

  186. ##$strPOST

  187. # = join("&"#$aPOST

  188. );  
  189. ## }  

    ########## curl_setopt(###$oCurl### # ##,CURLOPT_URL,######$url######);  #####################curl_setopt(###$oCurl######, CURLOPT_RETURNTRANSFER, 1);  ##########
  190. curl_setopt($oCurl#, CURLOPT_POST,true);  

  191. curl_setopt($oCurl, CURLOPT_POSTFIELDS,#$strPOST #);  

  192. #$sContent#=curl_exec($oCurl) ;  

  193. #$aStatus#=curl_getinfo($oCurl) ;  

  194. curl_close(

    $oCurl);  

  195. if(intval##(# ) ##$aStatus["http_code"])==200){  

  196. #return
  197.  $sContent;  ################# # #返回 假;  

    #
  198.  }  

  199. # }  





# }  
  1. [php]

  2. [php]# # 看法 plain 複製

  3. 。空間微信\控制器;  

  4. 使用 Wechat\Controller\ParentController;  

  5. /**

     
  6.  * 微信支付測試控制器 

    ###################################################################################################### #### * @file TestController.class.php### ##################### * @author Gary ## # ###################### * @date 2015年8月4日### ################ ##### * @todu### ###################### */######  ##########
  7. class TestController #extends ParentController {  

  8. ## 
  9. #private
  10.  #$_order_body = 'xxx';  

    #私人
  11. #$_order_goods_tag=='xxx';  

  12. #public

  13. #function
  14.  __construct(){  父::__construct();  

  15.  

    require_once ROOT_PATH."Api/lib/WxPay.Api.php" ;  

  16. #require_once

    #ROOT_PATH.

    "Api/lib/WxPay.JsApiPay.php"
  17. ;  

    ######### }  ##################  ###########################################################################################
  18.  public #function index(){  

  19.  
  20. //①、取得使用者openid
  21.     $tools = 

  22. new
  23.  \JsApiPay();  

     
  24. $openId
  25.  = $tools->GetOpenid();   

  26. //②、統一訂單
  27.   

     
  28. $input
  29. new \WxPayUnifiedOrder();   

     
  30. //商品說明
  31.   

     ###$input######->SetBody(######$this## ####->_order_body);  ###################### ###//附加數據,可以新增自己需要的數據,微信回非同步回調時會附加這個資料######  ##########
  32.  $input->SetAttach('xxx');  

  33.  //商家訂單號碼#  

  34.  $out_trade_no = \WxPayConfig::MCHID.date("YmdHis"#);

  35.  $input->SetOut_trade_no($out_trade_no #);  

  36.  //總金額,訂單總金額,只能為整數,單位為分 

  37. ## $input->SetTotal_fee(1);  

  38. //交易起始時間  

  39.  ## $input

    ->SetTime_start(
  40. date

    #("YmdHis"));  

    ############### ###//交易結束時間######  #########
  41.  $input->SetTime_expire(date(#"YmdHis ", time() + 600));  

  42. //商品標記

  43.  $input->SetGoods_tag($this #->_order_goods_tag);  

  44. //通知位址,接收微信支付非同步通知回呼位址 SITE_URL=http://test .paywechat.com/Charge  

  45.  $notify_url# = SITE_URL. '/index.php/Test/notify.html';  

  46. $input->SetNotify_url(##$notify_url);  

  47.  / /交易類型  

  48. $input->SetTrade_type("JSAPI");  

  49. $input##->SetOpenid( $openId);  #

  50.  $order = \WxPayApi::unifiedOrder($input#);  

  51.  $jsApiParameters

  52.  = 
  53. $tools->GetJsApiParameters($order);  

  54. //取得共享收貨位址js函數參數  

  55.  $editAddress = $tools #->GetEditAddressParameters();  

  56. #  

       $this->assign(

    'openId'
  57. ,

    $openId);   $this->assign(

    'jsApiParameters'######,## ####$jsApiParameters######);  ##################### ###$this#######->assign (######'editAddress'######,######$editAddress######);  #########
  58.  $this->display();   

  59. # }  

  60.   

  61.  /** 

  62.  * 非同步通知回呼方法 

  63.  */  

  64.  public #function# notify (){  

  65.  require_once ROOT_PATH.#"Api/lib/notify.php ";  

  66. $notify = #new \PayNotifyCallBack();  

  67.  $notify->Handle(false);  

  68.  //這裡的IsSuccess是我自訂的方法,後面我會貼出這個檔案的程式碼,供參考。   

  69.  $is_success = #$notify#->IsSuccess();   

    #
  70.  $bdata = $is_success['資料'];   

  71. ## //付款成功#  

  72. #if($is_success['程式碼'] == 1 ) {   

  73. $新聞 = 陣列(  

  74. 'touser'# => $bdata[ 'openid'],  

  75.   

    'msgtype'# => '新聞',  

  76. #  

    '新聞' = >  陣列 (  #

  77.   'articles'=> array (  

  78. #   array(  

  79.    #'title'  => '訂單付款成功',  

  80.    #   # #'description' => 

  81. "付款金額:{$bdata['total_fee']}\n"
  82. ##.  

    #   

    "微信訂單編號:{$bdata['transaction_id']}\n"
  83.   

    ##   'picurl' => 

    ''
  84. ,  

  85.    'url'

  86.  => 
  87. ''   

  88. ##   )  ##################  ##################  )  ##################  )  # #################  )  ################### );  #############################################################################################################################################
  89.  //寄送微信付款通知  

  90.  $this->sendCustomMessage($news);   

  91. # }else{//支付失敗#  

  92. # }  

  93. # }  

  94. ##  

  95.  

    /** 

  96.  * 付款成功頁面
  97.  

  98.  * 不可靠的回呼 

    ####### */######  ########## ############ ###public###### #######function###### ajax_PaySuccess(){  ############ ########## ###//訂單號碼######  ##################### ###$out_trade_no# ##### = I(######'post.out_trade_no'#######);  ##########
  99.  //付款金額  

  100. ## #$ total_fee = I('post.total_fee');  

  101. #/*相關邏輯處理*/  

  102. #  

  103. # }  

貼上範本HTML




[xhtml] view plain copy


  1. html>  

  2. #

    ######################## ##head######>######  ##########
  3. ##http-equiv##=「內容類型」 內容=#「text/html;charset=utf-8」 / >  

  4. meta  名稱="視窗" 內容=#"寬度=裝置寬度,初始比例=1“/>   

  5. 標題>微信支付範例-支付#標題## >  #

  6.  scripttype=

  7. "text/javascript"

  8. >
  9.   

  10.  //呼叫微信JS api 支付  

  11. # function jsApiCall()  

  12.  {  

  13. # {  

  14.  WeixinJSBridge.invoke(  

    # 'getBrandWCPayRequest',  
  15. ############################################# # {$jsApiParameters},  ################### function(res){  ################### WeixinJSBridge.log( res.err_msg);  ################### //取消付款  ################## if(### res.err_msg###### == 'get_brand_wcpay_request:cancel'){  ###################### //處理取消付款的事件邏輯  ############ //處理取消付款的事件邏輯  ############ //處理取消付款的事件邏輯  ### ############### }else if(###res.err_msg###### == "get_brand_wcpay_request:ok"){  ############ ########### /*使用上述方式判斷前端回傳,微信團隊鄭重提示:  ################## res.err_msg將在用戶支付成功後返回 ok,但不保證它絕對可靠。方法。 ######### alert(res.err_code+res.err_desc+res.err_msg);  ################## }  ################### }  ####### ########### );  ################## callpay()  
  16.  {  
  17. ## if (typeof
  18. WeixinJSBridge
  19.  == "未定義"){  

  20. ## if( document.addEventListener ){  

  21. document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);  

  22.  }else if (document.attachEvent){  

  23. document.attachEvent(' WeixinJSBridgeReady', jsApiCall);   

  24. document.attachEvent('onWeixinJSBridgeReady', jsApiCall);  ########### # ## jsApiCall();  

  25.  }  

  26. # }  

  27. ## //取得共享位址  

  28. #函數 editAddress()  

  29. # # {  
  30.  WeixinJSBridge.invoke(  
  31. #'editAddress',  
  32. #'editAddress',   ## {$editAddress},  

  33.  函數(res){   var value1 =

    ###res######.proviceFirstStageName;   ############ # ######## var ###value2###### = ######res######.addressCitySecondStageName;   ##########
  34. var value3 = res.addressCountiesThirdStageName;  

  35. ## var value4# = res.addressDetailInfo;  

  36. var tel# = = res.telNumber;   

  37. ##警報(值1+值2+值3+值4+「:」+電話);  

  38. }  

  39. #);  

  40.  }  

  41.  #window.onload

  42.  = 
  43. #function(){  

  44. # if (typeof 
  45. WeixinJSBridge
  46. # == 「未訂定」){  

    ############# if ( document. addEventListener){  ################## document.addEventListener('WeixinJSBridgeReady', editAddress, false);  ################## }else if (document.attachEvent){  ################## document.attachEvent(' WeixinJSBridgeReady', editAddress);   ################## document.attachEvent('onWeixinJSBridgeReady', editAddress);  ########### # ######## 編輯地址();  ######
  47.  }  

  48. # };  

  49.   

  50. >  

  51. head >  

  52. #body   

  53. br##/>   ##

  54.  fontcolor= "#9ACD32">#b>該筆訂單支付金額為span style#="color:#f00;font-size:50px">1分#span>

    ###### ########b######>############font#####>######< ;######br######/>############  ################################################################################################################## ######
  55. #p# 對齊=

  56. ## 「中心」>  ## ## ##>

  57. ###########################################################################################按鈕# ##### ######樣式######=######"寬度:210 像素;高度:50 像素;邊框半徑:15 像素;背景顏色:#FE6714;邊框: 0px #FE6714 實心; 遊標:指標; 顏色:白色; 字體大小:16px;「###### ######類型##### # ######onclick######=######"callpay()"###### #####>######立即支付### #########按鈕######>######  ################## ### ######################################################## ######p######>#######  #########
  58. body#>  

  59. #html>  






  1. #。 ##notify.php檔案程式碼,這裡有在官方文件裡新加入的自訂方法。

  2. [php] view plain copy

    #################################require_once## #### ROOT_PATH.######"Api/lib/WxPay.Api.php"######;  ##################### ####require_once###### ROOT_PATH.######'Api/lib/WxPay.Notify.php'######;  ############## ###########require_once###### ROOT_PATH.######'Api/lib/log.php'######;  ######### #
  3.   

  4. //初始化日志  

  5. $logHandlernew \CLogFileHandler(ROOT_PATH. "/logs/".date('Y-m-d').'.紀錄');  

  6. $log# = \Log::Init($logHandler

  7. #, 15);  

  8. ##  

    ##############class###### PayNotifyCallBack ######延伸###### WxPayNotify  #####################{  ###########################################################################################################################################################
  9. #受保護$para=##陣列 ('代碼'=>0,'資料'##=>##''#);  

  10. //查詢訂單

  11.  
  12. #public

     函數# Queryorder($transaction_id##)  

    # {  
  13. $input
  14. ## = 

    new \WxPayOrderQuery();  #$input

  15. ->SetTransaction_id(
  16. $transaction_id# #);  #$結果= \WxPayApi::orderQuery(

  17. $input
  18. );  #

  19. \Log::DEBUG("查詢:" . json_encode($結果#)) ;  

  20. if(array_key_exists(## ) ##"return_code"$結果#)  

  21. # &&array_key_exists("result_code"$result)  

  22. # && $結果["return_code"] == "成功"  

  23.  && $結果[#" result_code "] == "成功"#)  

  24. # {

  25. ## 

    return true;  

  26.  }  

    #

  27.  $this->para['code'##] = 0;  

  28.  $this->para['data'] = '';  

  29. return false;  

  30.  }  

  31.   

  32.  //重寫回呼處理函數   #public

  33.  
  34. function NotifyProcess(

  35. #$data
  36. , &$msg#)

     {  
  37. # \Log::DEBUG(" call back:" . json_encode($data));  

    ######################################################################################## # ###$notfiyOutput###### = ######array######();  ##########################
  38.   

  39. if(!array_key_exists("transaction_id"#$data)){  

  40. $msg = "輸入參數不正確";  

  41. $this->para['code'##] = 0;  

  42.  $this->para['data'] = '';  

  43. return false;  

  44.  }  

  45. //查詢訂單,判斷訂單真實性愛  

  46.  if(!#$this->Queryorder(##$ data["transaction_id"])){  

  47.  $msg = "訂單查詢失敗"#;  

  48.  $this->para['code'#] = 0;  

  49. $this->para[

    'data'
  50. ] = 

    ''

    ;  
  51.  
  52. return

     false;  

    #################################################################################################################### ####### }  ###################  ################## ###$this# #####->para[######'code'######] = 1;  #########
  53.  $this->para['data'##] = 

  54. # #$data

  55. ;  
  56. return

  57.  true;  
  58. # }  

    #  

# # /**
 

### * 自訂方法 偵測微信端是否回呼成功方法### ############################################################### ######### * @return multitype:number string### ##################### */######  ###################### ###public###### # #####function###### IsSuccess(){  ###################### ###return####### ################ ################ #### ###$this######->para;  ###################### }  ##################################################################################### ######}  ##################到這裡基本上完成,可以在微信端開啟######http://test.paywechat. com/Charge/index.php/Test/index/############相關推薦:#########

nodejs實作微信支付功能實例詳解

#Thinkphp整合微信支付功能

#怎麼為PC端網站加入這種微信支付功能

以上是PHP實作微信支付功能開發程式碼分享的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
可以在PHP會話中存儲哪些數據?可以在PHP會話中存儲哪些數據?May 02, 2025 am 12:17 AM

phpsessionscanStorestrings,數字,數組和原始物。

您如何開始PHP會話?您如何開始PHP會話?May 02, 2025 am 12:16 AM

tostartaphpsession,usesesses_start()attheScript'Sbeginning.1)placeitbeforeanyOutputtosetThesessionCookie.2)useSessionsforuserDatalikeloginstatusorshoppingcarts.3)regenerateSessiveIdStopreventFentfixationAttacks.s.4)考慮使用AttActAcks.s.s.4)

什麼是會話再生,如何提高安全性?什麼是會話再生,如何提高安全性?May 02, 2025 am 12:15 AM

會話再生是指在用戶進行敏感操作時生成新會話ID並使舊ID失效,以防會話固定攻擊。實現步驟包括:1.檢測敏感操作,2.生成新會話ID,3.銷毀舊會話ID,4.更新用戶端會話信息。

使用PHP會話時有哪些性能考慮?使用PHP會話時有哪些性能考慮?May 02, 2025 am 12:11 AM

PHP会话对应用性能有显著影响。优化方法包括:1.使用数据库存储会话数据,提升响应速度;2.减少会话数据使用,只存储必要信息;3.采用非阻塞会话处理器,提高并发能力;4.调整会话过期时间,平衡用户体验和服务器负担;5.使用持久会话,减少数据读写次数。

PHP會話與Cookie有何不同?PHP會話與Cookie有何不同?May 02, 2025 am 12:03 AM

PHPsessionsareserver-side,whilecookiesareclient-side.1)Sessionsstoredataontheserver,aremoresecure,andhandlelargerdata.2)Cookiesstoredataontheclient,arelesssecure,andlimitedinsize.Usesessionsforsensitivedataandcookiesfornon-sensitive,client-sidedata.

PHP如何識別用戶的會話?PHP如何識別用戶的會話?May 01, 2025 am 12:23 AM

phpIdentifiesauser'ssessionSessionSessionCookiesAndSessionId.1)whiwsession_start()被稱為,phpgeneratesainiquesesesessionIdStoredInacookInAcookInAcienamedInAcienamedphpsessIdontheuser'sbrowser'sbrowser.2)thisIdallowSphptpptpptpptpptpptpptpptoretoreteretrieetrieetrieetrieetrieetrieetreetrieetrieetrieetrieetremthafromtheserver。

確保PHP會議的一些最佳實踐是什麼?確保PHP會議的一些最佳實踐是什麼?May 01, 2025 am 12:22 AM

PHP會話的安全可以通過以下措施實現:1.使用session_regenerate_id()在用戶登錄或重要操作時重新生成會話ID。 2.通過HTTPS協議加密傳輸會話ID。 3.使用session_save_path()指定安全目錄存儲會話數據,並正確設置權限。

PHP會話文件默認存儲在哪裡?PHP會話文件默認存儲在哪裡?May 01, 2025 am 12:15 AM

phpsessionFilesArestoredIntheDirectorySpecifiedBysession.save_path,通常是/tmponunix-likesystemsorc:\ windows \ windows \ temponwindows.tocustomizethis:tocustomizEthis:1)useession_save_save_save_path_path()

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

WebStorm Mac版

WebStorm Mac版

好用的JavaScript開發工具

SublimeText3 英文版

SublimeText3 英文版

推薦:為Win版本,支援程式碼提示!

EditPlus 中文破解版

EditPlus 中文破解版

體積小,語法高亮,不支援程式碼提示功能

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

強大的PHP整合開發環境

Atom編輯器mac版下載

Atom編輯器mac版下載

最受歡迎的的開源編輯器