超碰中文网,91久久精品日日躁夜夜躁欧美,一区二区三区精品道,一区二区国产在线观看,亚洲精品中文字幕乱码一区二区,天天看片高清影视在线观看,久久99精品久久久久蜜桃,久久成人影视

VPS參考測評推薦
專注分享VPS主機優(yōu)惠信息
衡天云優(yōu)惠活動
熱網(wǎng)互聯(lián)2026年促銷活動
hostkvm優(yōu)惠促銷活動
zji優(yōu)惠促銷活動
QQGNET優(yōu)惠促銷活動
QQGNET優(yōu)惠促銷活動

調(diào)用微信封裝的微信簽名包(由微信jssdk簽名)的類庫

主機參考:VPS測評參考推薦/專注分享VPS服務(wù)器優(yōu)惠信息!若您是商家可以在本站進行投稿,查看詳情!此外我們還提供軟文收錄、PayPal代付、廣告贊助等服務(wù),查看詳情!
我們發(fā)布的部分優(yōu)惠活動文章可能存在時效性,購買時建議在本站搜索商家名稱可查看相關(guān)文章充分了解該商家!若非中文頁面可使用Edge瀏覽器同步翻譯!PayPal代付/收錄合作

本文主要介紹微信封裝的調(diào)用微信簽名包的類庫的相關(guān)資料,有需要的朋友可以參考一下。

廢話不多說,我直接把代碼發(fā)給你。具體代碼如下:

& lt?phpnamespace Home \ Model使用思考\模型;類微信模型擴展模型{ private $ _ token = & amp#39;& amp#39;;//令牌私有$ appidprivate $ appsecretpublic function _ _ construct(){ $ this -》;appid = C(& amp;#39;APPID & amp#39;);//微信官方賬號中的AppID $ this -》app secret = C(& amp;#39;APPSECRET & amp#39;);//微信官方賬號的秘鑰}//調(diào)用js-sdk的簽名包公共函數(shù)getsignpackage(){ $ JSAPI ticket = $ this -》getjsapi ticket();//注意,URL必須是動態(tài)獲取的,而不是硬編碼的。(獲取當(dāng)前網(wǎng)頁的URL)$ protocol =(!空($ _ SERVER【& amp;#39;HTTPS & amp;#39;】)& amp& amp$ _ SERVER【& amp;#39;HTTPS & amp;#39;] != = & amp#39;關(guān)閉& amp#39;| | $ _服務(wù)器【& amp#39;服務(wù)器端口。#39;] == 443) ?"https://& quot;:& quothttp://& quot;;$ url = & quot$ protocol $ _ SERVER【HTTP _ HOST】$ _ SERVER【REQUEST _ URI】& quot;;//timestamp $ timestamp = time();//隨機字符串獲取$ non centr = $ this -& gt;createnoncentr();//這里的參數(shù)順序應(yīng)該按照鍵值$ string = $ jsapi ticket = $ jsapi ticket & amp;noncestr = $ nonceStr & amp時間戳= $ timestamp & ampurl = $ url & quot;//生成的字符串為$ signature = sha1($ string)用于簽名;$ sign package = array(& quot;appId & quot= & gt$ this -》;appid非中心& quot= & gt$ nonceStr,& quot時間戳& quot= & gt$timestampurl & quot= & gt$url簽名& quot= & gt$signaturerawString&quot= & gt$ string);return $ signPackage}//使用會員卡接收的簽名包公共函數(shù)gethuiyansignpack(){ $ API ticket = $ this -》getApiTicket();//注意,URL必須是動態(tài)獲取的,而不是硬編碼的。(獲取當(dāng)前網(wǎng)頁的URL)$ protocol =(!空($ _ SERVER【& amp;#39;HTTPS & amp;#39;】)& amp& amp$ _ SERVER【& amp;#39;HTTPS & amp;#39;] != = & amp#39;關(guān)閉& amp#39;| | $ _服務(wù)器【& amp#39;服務(wù)器端口。#39;] == 443) ?"https://& quot;:& quothttp://& quot;;$ url = & quot$ protocol $ _ SERVER【HTTP _ HOST】$ _ SERVER【REQUEST _ URI】& quot;;//timestamp $ timestamp = time();//隨機字符串獲取//$ non centr = $ this -》;createnoncentr();//這里的參數(shù)順序要按照鍵值$ string = $ timestamp的ASCII碼升序排序。$ apiticket。汽車id & quot;//card_id是自己創(chuàng)建的會員卡的ID//生成的字符串為$ signature = sha1($ string)用于簽名;$ sign package = array(& quot;時間戳& quot= & gt$timestamp簽名& quot= & gt$signature、);return $ signPackage}//獲取會員卡的API _ ticket公共函數(shù)getapticket(){ $ data = JSON _ decode(file _ Get _ contents(“API _ ticket . JSON & quot;));if($ data -》;過期時間& lttime()){ $ access token = $ this -& gt;getAccessToken();$ url = & quothttps://api.weixin.qq.com/cgi-bin/ticket/getticket?類型= wx _卡& ampaccess _ token = $ access token & quot;;$ RES = JSON _ decode($ this -& gt;http get($ URL));$ ticket = $ res-& gt;車票;if($ ticket){ $ data -》;expire _ time = time()+7000;$ data -》;jsapi _ ticket = $ ticket$ FP = fopen(& quot;api _ ticket.json & quot,& quotw & quot);fwrite(FP,JSON _ encode(data));fclose($ FP);} } else { $ ticket = $ data -& gt;jsapi _ ticket} return $ ticket}//獲取隨機字符串私有函數(shù)createnoncentr($ length = 16){ $ chars =“abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz 0123456789 & quot;;$ str = & quot";for($ I = 0;$ i & lt$ length$ i++){ $ str。= substr($ chars,mt _ rand(0,strlen($ chars)-1),1);} return $ str}//Get訪問令牌公共函數(shù)getaccesstoken(){//將json字符串轉(zhuǎn)換為json對象(json_encode是將數(shù)組轉(zhuǎn)換為json字符串,JSON _ decode(& quot;",true)如果添加了true,則json字符串被轉(zhuǎn)換為php數(shù)組,如果未添加true,則被轉(zhuǎn)換為PHP對象)$ data = JSON _ decode(file _ get _ contents(“access _ token . JSON & quot;));if($ data -》;過期時間& lttime()){//如果是企業(yè),請使用以下URL獲取access _ token $ URL =“https://api.weixin.qq.com/cgi-bin/token?格蘭特類型=客戶端憑據(jù)& ampappid = $ this -& gt;appid & ampsecret = $ this -& gt;appsecret"$ RES = JSON _ decode($ this -& gt;http get($ URL));$ access _ token = $ res-& gt;access _ tokenif($ access _ token){ $ data -》;expire _ time = time()+7000;$ data -》;access _ token = $ access _ token$ FP = fopen(& quot;access _ token.json & quot,& quotw & quot);fwrite(FP,JSON _ encode(data));fclose($ FP);} } else { $ access _ token = $ data -& gt;access _ token} return $ access _ token}//Get JSAPI _ ticket(JSAPI _ ticket是微信官方賬號用來調(diào)用微信JS接口的臨時ticket)私有函數(shù)getJSAPI ticket(){//JSAPI _ ticket應(yīng)該全局存儲和更新。作為示例,應(yīng)將以下代碼寫入文件中:$ data = JSON _ decode(file _ get _ contents(“jsapi _ ticket . JSON & quot;));if($ data -》;過期時間& lttime()){ $ access token = $ this -& gt;getAccessToken();//如果是企業(yè)號碼,請使用以下URL獲取票證//$ URL =“https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?訪問令牌= $訪問令牌& quot;$ url = & quothttps://api.weixin.qq.com/cgi-bin/ticket/getticket?類型= jsapi & ampaccess _ token = $ access token & quot;;$ RES = JSON _ decode($ this -& gt;http get($ URL));$ ticket = $ res-& gt;車票;if($ ticket){ $ data -》;expire _ time = time()+7000;$ data -》;jsapi _ ticket = $ ticket$ FP = fopen(& quot;jsapi _ ticket.json & quot,& quotw & quot);fwrite(FP,JSON _ encode(data));fclose($ FP);} } else { $ ticket = $ data -& gt;jsapi _ ticket} return $ ticket}//獲取用戶的OpenID公共函數(shù)OpenID(){ $ URL = $ _ server【&;#39;HTTP _ HOST & amp#39;] .$ _ SERVER【& amp;#39;請求_ URI & amp;#39;];如果(!isset($ _ GET【& amp;#39;代碼&amp。#39;】){//獲取組裝的URL $ openidUrl = $ this -& gt;snsapi _ base($ URL);重定向($ openidUrl);} else { $ OpenID access _ token = $ this -& gt;OpenID access _ token($ _ GET【& amp;#39;代碼&amp。#39;]);返回$ openidAccess _ token} }//獲取微信用戶的OPNID公共函數(shù)Get OpenID($ OpenID,$ access _ token){ $ userinfo = $ this -》Get userinfo($ OpenID,$ access _ token);return $ userInfo}公共函數(shù)snsapi _ base($ redirect _ uri,$ scope = & quotsnsapi _ userinfo & quot,$ state = 0){ $ appId = $ this -& gt;appid$ url = & quothttps://open.weixin.qq.com/connect/oauth2/authorize";$url。= & quot?appid = $ appId & quot;$url。= & quot& amp重定向uri = http://$ redirect _ uri & quot;;$url。= & quot& ampresponse_type=code"$url。= & quot& ampscope = $ scope & quot;$url。= & quot& ampstate = $ state #微信重定向& quot;返回$ url}公共函數(shù)OpenID access _ token($ code){ $ appId = $ this -& gt;appid$ app secret = $ this -& gt;appsecret$ url = & quothttps://api.weixin.qq.com/sns/oauth2/access_token? appId = $ appId & amp;secret = $ appSecret & ampcode = $ code & ampgrant _ type = authorization _ code & quot;返回JSON _ decode($ this -》;http get($ URL),true);}//獲取用戶信息公共函數(shù)Get userinfo($ OpenID,$ access _ token){ $ URL =“https://api.weixin.qq.com/sns/userinfo? access _ token = $ access _ token & amp;openid = $ openid & amplang = zh _ CN & quot;返回JSON _ decode($ this -》;http get($ URL),true);//request}私有函數(shù)http get($ URL){ $ curl = curl _ init();curl _ setopt($ curl,CURLOPT_RETURNTRANSFER,true);curl _ setopt($ curl,CURLOPT_TIMEOUT,500);curl _ setopt($ curl,CURLOPT_SSL_VERIFYPEER,false);curl _ setopt($ curl,CURLOPT_SSL_VERIFYHOST,false);curl _ setopt($ curl,CURLOPT_URL,$ URL);$ RES = curl _ exec($ curl);curl _ close($ curl);return $ res}}

這幾篇文章你可能也喜歡:

本文由主機參考刊發(fā),轉(zhuǎn)載請注明:調(diào)用微信封裝的微信簽名包(由微信jssdk簽名)的類庫 http://www.k2270.com/107097.html

【騰訊云】領(lǐng)8888元采購禮包,搶爆款云服務(wù)器 每月 9元起,個人開發(fā)者加享折上折!
打賞
轉(zhuǎn)載請注明原文鏈接:主機參考 » 調(diào)用微信封裝的微信簽名包(由微信jssdk簽名)的類庫
主機參考僅做資料收集,不對商家任何信息及交易做信用擔(dān)保,購買前請注意風(fēng)險,有交易糾紛請自行解決!請查閱:特別聲明

評論 搶沙發(fā)

評論前必須登錄!