| 主機參考:VPS測評參考推薦/專注分享VPS服務器優(yōu)惠信息!若您是商家可以在本站進行投稿,查看詳情!此外我們還提供軟文收錄、PayPal代付、廣告贊助等服務,查看詳情! |
| 我們發(fā)布的部分優(yōu)惠活動文章可能存在時效性,購買時建議在本站搜索商家名稱可查看相關文章充分了解該商家!若非中文頁面可使用Edge瀏覽器同步翻譯!PayPal代付/收錄合作 |
這篇文章是我自己寫的,是微信第三方平臺開發(fā)實現(xiàn)的。代碼完整,每一步都有詳細介紹,供大家參考。
第一步:申請微信開放平臺賬號,創(chuàng)建第三方平臺。




第二步:微信官方賬號/小程序授權給第三方平臺。
lt?Php/**微信第三方平臺授權流程*/namespace app \ home \ controller;類Weixin擴展了Common { private $ appid = # 39wx3e * * * * * * 165c # 39;//第三方平臺應用appid private $ appsecret = # 3913e * * * * * * * * * * * d039 # 39;;//第三方平臺應用appsecret private $ token = # 39ePF58 * * * * * * Q2Ae # 39;//第三方平臺應用令牌(消息驗證令牌)private $ encodingaskey = # 39bzH * * * FCamD # 39;//第三方平臺應用密鑰(消息加解密密鑰)private $ component _ ticket = # 39票@ * * xv-g # 39;;//微信后臺推送的ticket用于獲取第三方平臺接口調(diào)用憑證。/* *代碼掃描授權。注意,這個網(wǎng)址必須放在頁面中間,用戶不能跳轉(zhuǎn)程序。否則,“請確認授權門戶頁面所在的域名,與授權后回調(diào)頁面的域名相同......”錯誤* @ paramstring $ redirect _ uri:掃碼成功后回調(diào)地址* @ paramint $ auth _ type:授權類型,1個微信官方賬號,2個小程序,3個微信官方賬號/小程序同時顯示。默認情況下,所有未傳遞的參數(shù)都顯示*/public function start auth($ redirect _ uri,$ auth _ type = 3){ $ URL = " https://mp.weixin.qq.com/cgi-bin/componentloginpage?組件_ appid = 。$ this - gt;appid。" 預認證代碼= 。$ this - gt;get_pre_auth_code()。" redirect _ uri = 。urlencode($redirect_uri)。" auth _ type = 。$ auth _ type返回$ url}/* *獲取第三方平臺access_token *注意這個值要保存,但是這里不保存代碼*/私有函數(shù)Get _ component _ access _ token(){ $ URL = " https://API . weixin . QQ . com/CG i-bin/component/API _ component _ token ;;$ data = # 39{ component_appid: '。$ this - gt;appid。'", component _ appsecret : '。$ this - gt;appsecret。'", 組件_驗證_票證 : '。$ this - gt;組件_票證。'"}';$ ret = JSON _ decode($ this - gt;https_post($url,$ data));if($ ret - gt;errcode = = 0){ return $ ret - gt;組件_訪問_令牌;} else { return $ ret - gt;錯誤代碼;}}/* *第三方平臺獲取預授權碼pre _ auth _ code */私有函數(shù)get _ pre _ auth _ code(){ $ URL = " https://API . weixin . QQ . com/CG i-bin/component/API _ create _ preauthcode?組件訪問令牌= 。$ this - gt;get_component_access_token()。$ data = # 39{ component_appid: '。$ this - gt;appid。'"}';$ ret = JSON _ decode($ this - gt;https_post($url,$ data));if($ ret - gt;errcode = = 0){ return $ ret - gt;預認證代碼;} else { return $ ret - gt;錯誤代碼;}}/* *發(fā)起POST網(wǎng)絡提交* @params string $url:網(wǎng)絡地址* @ params JSON $ data:JSON格式數(shù)據(jù)發(fā)送*/private function https _ POST($ URL,$ data){ $ curl = curl _ init();curl_setopt($curl,CURLOPT_URL,$ URL);如果(!empty($ data)){ curl _ setopt($ curl,CURLOPT_POST,1);curl_setopt($curl,CURLOPT_POSTFIELDS,$ data);} curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);$ output = curl _ exec($ curl);curl _ close($ curl);返回$ output}/* * Initiate GET網(wǎng)絡提交* @ paramstring $ URL:network address */private function https _ GET($ URL){ $ curl = curl _ init();curl_setopt($curl,CURLOPT_URL,$ URL);curl_setopt($curl,CURLOPT_RETURNTRANSFER,TRUE);curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,F(xiàn)ALSE);curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,F(xiàn)ALSE);curl_setopt($curl,CURLOPT_HEADER,F(xiàn)ALSE);curl_setopt($curl,CURLOPT_TIMEOUT,60);if(curl _ errno($ curl)){ return # 39;Errno # 39。curl _ error($ curl);} else { $ result = curl _ exec($ curl);} curl _ close($ curl);返回$ result} } lt?Php/**接收微信推送的票值并取消授權*/namespace app \ home \ controller;使用think \ Db類Openoauth擴展了Common { private $ appid = # 39wx3e * * * * * * 165c # 39;//第三方平臺應用appid private $ appsecret = # 3913e * * * * * * * * * * * d039 # 39;;//第三方平臺應用appsecret private $ token = # 39ePF58 * * * * * * Q2Ae # 39;//第三方平臺應用令牌(消息驗證令牌)private $ encodingaskey = # 39bzH * * * FCamD # 39;//第三方平臺應用密鑰(消息加解密密鑰)private $ component _ ticket = # 39票@ * * xv-g # 39;;//后臺微信推送的ticket用于獲取第三方平臺接口調(diào)用憑證。/* *接收微信官方推送的消息(10分鐘一次)*這里需要介紹一下微信官方提供的密碼加密樣本包*官方文檔:https://open.weixin.qq.com/cgi-bin/showdocument? action = dir _ list ;t =資源/資源列表 驗證= 1 id = open1419318479 token = Lang=zh_CN *樣例包下載:https://wximg.gtimg.com/shake_tv/mpwiki/cryptoDemo.zip */public function index(){ $ encryptmsg = file _ get _ contents(" PHP://input ;);$ XML _ tree = new \ DOM document();$ XML _ tree - gt;load XML($ encrypt msg);$ XML _ array = $ XML _ tree - gt;getElementsByTagName( ;加密 );$ encrypt = $ XML _ array - gt;item(0)->nodeValue需要一次( # 39;wxBizMsgCrypt.php # 39);$ prcrypt = new \ prcrypt($ this - gt;encodingAesKey);$ postData = $ PRP crypt - gt;解密($encrypt,$ this - gt;appid);if($ postData])- gt;訂單( # 39;create _ time # 39,'desc # 39;)->;價值( # 39;auditid # 39);if($ auditid){ echo # 39; lt腳本 gt警報( 對于要處理的版本,請在提交新的審核之前處理好該版本的相關事宜。審計id: # 39;。$auditid。'");history . back(); lt/script gt;';} else { if($mini - gt;submit review()){ echo # 39; lt腳本 gt警報( 小程序提交審核操作成功”);history . back(); lt/script gt;';} else { echo # 39 lt腳本 gt警報( 小程序無法提交審核操作。請查看日志”);history . back(); lt/script gt;';} } } else if($ action = = # 39;getAudit # 39){//查詢指定版本$ auditid = input( # 39;auditid # 39);if($ auditid){ if($ mini - gt;getAuditStatus($ auditid)){ $ audit = Db::name( # 39;wxminiprogram _ audit # 39)->;其中(])- gt;訂單( # 39;create _ time # 39,'desc # 39;)->;價值( # 39;auditid # 39);if($ auditid){ echo # 39; lt腳本 gt警報( 對于要處理的版本,請在發(fā)布該版本之前處理好該版本的相關事宜。審計id: # 39;。$auditid。'");history . back(); lt/script gt;';} else { $ errcode = $ mini - gt;發(fā)布();if($ errcode){ echo # 39; lt腳本 gt警報( 發(fā)行版”);history . back(); lt/script gt;';} else { echo # 39 lt腳本 gt警報( 發(fā)布失敗,錯誤代碼: # 39;。$errcode。'");history . back(); lt/script gt;';}}}}}基本上就是通過這兩個價值來實現(xiàn)小程序代工商
-- Adminer 4.6.2 MySQL轉(zhuǎn)儲集名稱utf8SET time _ zone = # 39+00:00';SET foreign _ key _ checks = 0;SET sql _ mode = # 39NO _ AUTO _ VALUE _ ON _ ZERO # 39;如果存在“wxminiprograms ”,則刪除表;CREATE TABLE ` wxminiprograms `( ` id ` int(10)unsigned NOT NULL AUTO _ INCREMENT COMMENT # 39;ID # 39,` uid` int(10) unsigned NOT NULL注釋 # 39;用戶ID # 39,` nick_name` varchar(45)默認空注釋 # 39;微信小程序名稱 # 39;,' alias ' varchar(45)默認空注釋 # 39;別名 # 39;,` token ' varchar(45)默認空注釋 # 39;平臺產(chǎn)生的代幣價值 # 39;,` head_img` varchar(255)默認空注釋 # 39;微信小程序頭像 # 39;,` verify_type_info` tinyint(1)默認空注釋 # 39;授權方認證類型,-1表示未認證,0表示微信認證 # 39;,` is_show` tinyint(1)默認 # 39;0'評論 # 39;顯示,0顯示,1隱藏 # 39;,` user_name` varchar(45)默認空注釋 # 39;原始ID # 39,` qrcode_url` varchar(255)默認空注釋 # 39;二維碼的網(wǎng)址 # 39;,` business_info` varchar(255)默認空注釋 # 39;Json格式。用于了解以下功能的開啟狀態(tài)(0表示未開啟,1表示已開啟):open_store:是否開啟微信店鋪功能open_scan:是否開啟微信商品掃描功能open_pay:是否開啟微信支付功能open_card:是否開啟微信卡券功能open_shake:是否開啟微信搖一搖功能 # 39;,` idc` int(10)無符號缺省空注釋 # 39;idc # 39,` principal_name` varchar(45)默認空注釋 # 39;小程序的主題名 # 39;,` signature ' varchar(255)默認空注釋 # 39;賬戶介紹 # 39;,` miniprograminfo` varchar(255)默認空注釋 # 39;Json格式。是否被小程序類型授權,包括網(wǎng)絡小程序設置的各個服務器的域名 # 39;,` func _ info` longtext COMMENT # 39Json格式。權限列表,ID號17到19分別代表:17。賬戶管理權限18。開發(fā)管理許可。客戶服務消息管理權限。請注意:1)該字段的返回不會考慮小程序是否有該權限集的權限(因為其中部分可能有)。',` authorizer_appid` varchar(45)默認空注釋 # 39;Applet appid # 39,` authorizer _ access _ token ` varchar(255)默認空注釋 # 39;授權方接口調(diào)用憑證(該返回值僅在被授權的微信官方賬號或小程序有API權限時可用),簡稱token # 39;,` authorizer _ expires ` int(10)unsigned默認空注釋 # 39;刷新的有效期 # 39;,` authorizer _ refresh _ token ' varchar(255)默認空注釋 # 39;調(diào)用接口憑證刷新令牌 # 39;,` create _ time ` TIMESTAMP NOT NULL UPDATE CURRENT_TIMESTAMP上的默認CURRENT _ TIMESTAMP注釋 # 39;授權時間 # 39;,主鍵(` id `))ENGINE = InnoDB DEFAULT CHARSET = utf8 COMMENT = # 39;微信小程序授權列表 # 39;;--2018-07-25 09:32:49 wxminiprogram _ audit數(shù)據(jù)表,保存提交審核的小程序
-- Adminer 4.6.2 MySQL轉(zhuǎn)儲集名稱utf8SET time _ zone = # 39+00:00';SET foreign _ key _ checks = 0;SET sql _ mode = # 39NO _ AUTO _ VALUE _ ON _ ZERO # 39;如果存在“wxminiprogram_audit ”,則刪除表;CREATE TABLE ` wxminiprogram _ audit `( ` id ` int(10)unsigned NOT NULL AUTO _ INCREMENT COMMENT # 39;ID # 39,` appid ' varchar(45)NOT NULL注釋 # 39;Applet appid # 39,' auditid ' varchar(45)NOT NULL注釋 # 39;審計編號 # 39;,` status ` tinyint(1)unsigned NOT NULL默認值 # 39;3'評論 # 39;審批狀態(tài),其中0為審批成功,1為審批失敗,2為審批中,3為已提交審批 # 39;,' reason ' varchar(255)默認空注釋 # 39;當status=1時,審計被拒絕,返回拒絕原因 # 39;,` create _ time ` TIMESTAMP NOT NULL UPDATE CURRENT_TIMESTAMP上的默認CURRENT _ TIMESTAMP注釋 # 39;提交時間 # 39;,主鍵(` id `))ENGINE = InnoDB DEFAULT CHARSET = utf8 COMMENT = # 39;微信提交審核的小程序 # 39;;-- 2018-07-25 09:35:070] != 0) { return $postData[0]; } else { $msg = $postData[1]; $xml = new \DOMDocument(); $xml->loadXML($msg); $array_a = $xml->getElementsByTagName(&;InfoType&;); $infoType = $array_a->item(0)->nodeValue; if ($infoType == &;unauthorized&;) { //取消公眾號/小程序授權 $array_b = $xml->getElementsByTagName(&;AuthorizerAppid&;); $AuthorizerAppid = $array_b->item(0)->nodeValue; //公眾號/小程序appid $where = array(&;type&; => 1, &;appid&; => $AuthorizerAppid); $save = array(&;authorizer_access_token&; => &;&;, &;authorizer_refresh_token&; => &;&;, &;authorizer_expires&; => 0); Db::name(&;wxuser&;)->where($where)->update($save); //公眾號取消授權 Db::name(&;wxminiprograms&;)->where('authorizer_appid',$AuthorizerAppid)->update($save); //小程序取消授權 } else if ($infoType == &;component_verify_ticket&;) { //微信官方推送的ticket值 $array_e = $xml->getElementsByTagName(&;ComponentVerifyTicket&;); $component_verify_ticket = $array_e->item(0)->nodeValue; if (Db::name(&;weixin_account&;)->where(array(&;type&; => 1))->update(array(&;component_verify_ticket&; => $component_verify_ticket, &;date_time&; => time()))) { $this->updateAccessToken($component_verify_ticket); echo &;success&;; } } } } /* * 更新component_access_token * @params string $component_verify_ticket * */ private function updateAccessToken($component_verify_ticket) { $weixin_account = Db::name('weixin_account')->where(['type'=>1])->field('id,appId,appSecret,component_access_token,token_expires')->find(); if($weixin_account['token_expires'] <= time() ) { $apiUrl = 'https://api.weixin.qq.com/cgi-bin/component/api_component_token'; $data = '{&;component_appid&;:&;'.$weixin_account['appId'].'&; ,&;component_appsecret&;: &;'.$weixin_account['appSecret'].'&;,&;component_verify_ticket&;: &;'.$component_verify_ticket.'&;}'; $json = json_decode(_request($apiUrl,$data)); if(isset($json->component_access_token)) { Db::name('weixin_account')->where(['id'=>$weixin_account['id']])->update(['component_access_token'=>$json->component_access_token,'token_expires'=>time()+7200]); } } }}<?php/** 代小程序?qū)崿F(xiàn)業(yè)務*/namespace app\home\model;use think\Model;use think\Db;use think\Cache;class Miniprogram extends Model{ private $thirdAppId; //開放平臺appid private $encodingAesKey; //開放平臺encodingAesKey private $thirdToken; //開放平臺token private $thirdAccessToken; //開放平臺access_token private $authorizer_appid; private $authorizer_access_token; private $authorizer_refresh_token; public function __construct($appid) { $weixin_account = Db::name('weixin_account')->where(['type' => 1])->field('token,encodingAesKey,appId,component_access_token')->find(); if ($weixin_account) { $this->thirdAppId = $weixin_account['appId']; $this->encodingAesKey = $weixin_account['encodingAesKey']; $this->thirdToken = $weixin_account['token']; $this->thirdAccessToken = $weixin_account['component_access_token']; $miniprogram = Db::name('wxminiprograms')->where('authorizer_appid',$appid) ->field('authorizer_access_token,authorizer_refresh_token,authorizer_expires')->find(); if($miniprogram){ $this->authorizer_appid = $appid; if(time() > $miniprogram['authorizer_expires']){ $miniapp = $this->update_authorizer_access_token($appid,$miniprogram['authorizer_refresh_token']); if($miniapp) { $this->authorizer_access_token = $miniapp->authorizer_access_token; $this->authorizer_refresh_token = $miniapp->authorizer_refresh_token; } else { $this->errorLog(&;更新小程序access_token失敗,appid:&;.$this->authorizer_appid,''); exit; } } else { $this->authorizer_access_token = $miniprogram['authorizer_access_token']; $this->authorizer_refresh_token = $miniprogram['authorizer_refresh_token']; } } else { $this->errorLog(&;小程序不存在,appid:&;.$this->authorizer_appid,''); exit; } } else { $this->errorLog(&;請增加微信第三方公眾號平臺賬戶信息&;,''); exit; } } /* * 設置小程序服務器地址,無需加https前綴,但域名必須可以通過https訪問 * @params string / array $domains : 域名地址。只接收一維數(shù)組。 * */ public function setServerDomain($domain = 'test.moh.cc') { $url = &;https://api.weixin.qq.com/wxa/modify_domain?access_token=&;.$this->authorizer_access_token; if(is_array($domain)) { $https = ''; $wss = ''; foreach ($domain as $key => $value) { $https .= '&;https://'.$value.'&;,'; $wss .= '&;wss://'.$value.'&;,'; } $https = rtrim($https,','); $wss = rtrim($wss,','); $data = '{ &;action&;:&;add&;, &;requestdomain&;:['.$https.'], &;wsrequestdomain&;:['.$wss.'], &;uploaddomain&;:['.$https.'], &;downloaddomain&;:['.$https.'] }'; } else { $data = '{ &;action&;:&;add&;, &;requestdomain&;:&;https://'.$domain.'&;, &;wsrequestdomain&;:&;wss://'.$domain.'&;, &;uploaddomain&;:&;https://'.$domain.'&;, &;downloaddomain&;:&;https://'.$domain.'&; }'; } $ret = json_decode(https_post($url,$data)); if($ret->errcode == 0) { return true; } else { $this->errorLog(&;設置小程序服務器地址失敗,appid:&;.$this->authorizer_appid,$ret); return false; } } /* * 設置小程序業(yè)務域名,無需加https前綴,但域名必須可以通過https訪問 * @params string / array $domains : 域名地址。只接收一維數(shù)組。 * */ public function setBusinessDomain($domain = 'test.moh.cc') { $url = &;https://api.weixin.qq.com/wxa/setwebviewdomain?access_token=&;.$this->authorizer_access_token; if(is_array($domain)) { $https = ''; foreach ($domain as $key => $value) { $https .= '&;https://'.$value.'&;,'; } $https = rtrim($https,','); $data = '{ &;action&;:&;add&;, &;webviewdomain&;:['.$https.'] }'; } else { $data = '{ &;action&;:&;add&;, &;webviewdomain&;:&;https://'.$domain.'&; }'; } $ret = json_decode(https_post($url,$data)); if($ret->errcode == 0) { return true; } else { $this->errorLog(&;設置小程序業(yè)務域名失敗,appid:&;.$this->authorizer_appid,$ret); return false; } } /* * 成員管理,綁定小程序體驗者 * @params string $wechatid : 體驗者的微信號 * */ public function bindMember($wechatid) { $url = &;https://api.weixin.qq.com/wxa/bind_tester?access_token=&;.$this->authorizer_access_token; $data = '{&;wechatid&;:&;'.$wechatid.'&;}'; $ret = json_decode(https_post($url,$data)); if($ret->errcode == 0) { return true; } else { $this->errorLog(&;綁定小程序體驗者操作失敗,appid:&;.$this->authorizer_appid,$ret); return false; } } /* * 成員管理,解綁定小程序體驗者 * @params string $wechatid : 體驗者的微信號 * */ public function unBindMember($wechatid) { $url = &;https://api.weixin.qq.com/wxa/unbind_tester?access_token=&;.$this->authorizer_access_token; $data = '{&;wechatid&;:&;'.$wechatid.'&;}'; $ret = json_decode(https_post($url,$data)); if($ret->errcode == 0) { return true; } else { $this->errorLog(&;解綁定小程序體驗者操作失敗,appid:&;.$this->authorizer_appid,$ret); return false; } } /* * 成員管理,獲取小程序體驗者列表 * */ public function listMember() { $url = &;https://api.weixin.qq.com/wxa/memberauth?access_token=&;.$this->authorizer_access_token; $data = '{&;action&;:&;get_experiencer&;}'; $ret = json_decode(https_post($url,$data)); if($ret->errcode == 0) { return $ret->members; } else { $this->errorLog(&;獲取小程序體驗者列表操作失敗,appid:&;.$this->authorizer_appid,$ret); return false; } } /* * 為授權的小程序帳號上傳小程序代碼 * @params int $template_id : 模板ID * @params json $ext_json : 小程序配置文件,json格式 * @params string $user_version : 代碼版本號 * @params string $user_desc : 代碼描述 * */ public function uploadCode($template_id = 1, $user_version = 'v1.0.0', $user_desc = &;魔盒CMS小程序模板庫&;) { $ext_json = json_encode('{&;extEnable&;: true,&;extAppid&;: &;wx572****bfb&;,&;ext&;:{&;appid&;: &;'.$this->authorizer_appid.'&;}}'); $url = &;https://api.weixin.qq.com/wxa/commit?access_token=&;.$this->authorizer_access_token; $data = '{&;template_id&;:&;'.$template_id.'&;,&;ext_json&;:'.$ext_json.',&;user_version&;:&;'.$user_version.'&;,&;user_desc&;:&;'.$user_desc.'&;}'; $ret = json_decode(https_post($url,$data)); if($ret->errcode == 0) { return true; } else { $this->errorLog(&;為授權的小程序帳號上傳小程序代碼操作失敗,appid:&;.$this->authorizer_appid,$ret); return false; } } /* * 獲取體驗小程序的體驗二維碼 * @params string $path : 指定體驗版二維碼跳轉(zhuǎn)到某個具體頁面 * */ public function getExpVersion($path = '') { if($path){ $url = &;https://api.weixin.qq.com/wxa/get_qrcode?access_token=&;.$this->authorizer_access_token.&;path=&;.urlencode($path); } else { $url = &;https://api.weixin.qq.com/wxa/get_qrcode?access_token=&;.$this->authorizer_access_token; } $ret = json_decode(https_get($url)); if($ret->errcode) { $this->errorLog(&;獲取體驗小程序的體驗二維碼操作失敗,appid:&;.$this->authorizer_appid,$ret); return false; } else { return $url; } } /* * 提交審核 * @params string $tag : 小程序標簽,多個標簽以空格分開 * @params strint $title : 小程序頁面標題,長度不超過32 * */ public function submitReview($tag = &;魔盒CMS 微信投票 微網(wǎng)站 微信商城&; ,$title = &;魔盒CMS微信公眾號營銷小程序開發(fā)&;) { $first_class = '';$second_class = '';$first_id = 0;$second_id = 0; $address = &;pages/index/index&;; $category = $this->getCategory(); if(!empty($category)) { $first_class = $category[0]->first_class ? $category[0]->first_class : '' ; $second_class = $category[0]->second_class ? $category[0]->second_class : ''; $first_id = $category[0]->first_id ? $category[0]->first_id : 0; $second_id = $category[0]->second_id ? $category[0]->second_id : 0; } $getpage = $this->getPage(); if(!empty($getpage) isset($getpage[0])) { $address = $getpage[0]; } $url = &;https://api.weixin.qq.com/wxa/submit_audit?access_token=&;.$this->authorizer_access_token; $data = '{ &;item_list&;:[{ &;address&;:&;'.$address.'&;, &;tag&;:&;'.$tag.'&;, &;title&;:&;'.$title.'&;, &;first_class&;:&;'.$first_class.'&;, &;second_class&;:&;'.$second_class.'&;, &;first_id&;:&;'.$first_id.'&;, &;second_id&;:&;'.$second_id.'&; }] }'; $ret = json_decode(https_post($url,$data)); if($ret->errcode == 0) { Db::name('wxminiprogram_audit')->insert([ 'appid'=>$this->authorizer_appid, 'auditid'=>$ret->auditid, 'create_time'=>date('Y-m-d H:i:s') ]); return true; } else { $this->errorLog(&;小程序提交審核操作失敗,appid:&;.$this->authorizer_appid,$ret); return false; } } /* * 小程序?qū)徍顺坊? * 單個帳號每天審核撤回次數(shù)最多不超過1次,一個月不超過10次。 * */ public function unDoCodeAudit() { $url = &;https://api.weixin.qq.com/wxa/undocodeaudit?access_token=&;.$this->authorizer_access_token; $ret = json_decode(https_get($url)); if($ret->errcode == 0) { return true; } else { $this->errorLog(&;小程序?qū)徍顺坊夭僮魇。琣ppid:&;.$this->authorizer_appid,$ret); return false; } } /* * 查詢指定版本的審核狀態(tài) * @params string $auditid : 提交審核時獲得的審核id * */ public function getAuditStatus($auditid) { $url = &;https://api.weixin.qq.com/wxa/get_auditstatus?access_token=&;.$this->authorizer_access_token; $data = '{&;auditid&;:&;'.$auditid.'&;}'; $ret = json_decode(https_post($url,$data)); if($ret->errcode == 0) { $reason = $ret->reason ? $ret->reason : ''; Db::name('wxminiprogram_audit')->where(['appid'=>$this->authorizer_appid,'auditid'=>$auditid])->update([ 'status'=>$ret->status, 'reason'=>$reason ]); return true; } else { $this->errorLog(&;查詢指定版本的審核狀態(tài)操作失敗,appid:&;.$this->authorizer_appid,$ret); return false; } } /* * 查詢最新一次提交的審核狀態(tài) * */ public function getLastAudit() { $url = &;https://api.weixin.qq.com/wxa/get_latest_auditstatus?access_token=&;.$this->authorizer_access_token; $ret = json_decode(https_get($url)); if($ret->errcode == 0) { $reason = $ret->reason ? $ret->reason : ''; Db::name('wxminiprogram_audit')->where(['appid'=>$this->authorizer_appid,'auditid'=>$ret->auditid])->update([ 'status'=>$ret->status, 'reason'=>$reason ]); return $ret->auditid; } else { $this->errorLog(&;查詢最新一次提交的審核狀態(tài)操作失敗,appid:&;.$this->authorizer_appid,$ret); return false; } } /* * 發(fā)布已通過審核的小程序 * */ public function release() { $url = &;https://api.weixin.qq.com/wxa/release?access_token=&;.$this->authorizer_access_token; $data = '{}'; $ret = json_decode(https_post($url,$data)); if($ret->errcode == 0) { return true; } else { $this->errorLog(&;發(fā)布已通過審核的小程序操作失敗,appid:&;.$this->authorizer_appid,$ret); return $ret->errcode; } } /* * 獲取授權小程序帳號的可選類目 * */ private function getCategory() { $url = &;https://api.weixin.qq.com/wxa/get_category?access_token=&;.$this->authorizer_access_token; $ret = json_decode(https_get($url)); if($ret->errcode == 0) { return $ret->category_list; } else { $this->errorLog(&;獲取授權小程序帳號的可選類目操作失敗,appid:&;.$this->authorizer_appid,$ret); return false; } } /* * 獲取小程序的第三方提交代碼的頁面配置 * */ private function getPage() { $url = &;https://api.weixin.qq.com/wxa/get_page?access_token=&;.$this->authorizer_access_token; $ret = json_decode(https_get($url)); if($ret->errcode == 0) { return $ret->page_list; } else { $this->errorLog(&;獲取小程序的第三方提交代碼的頁面配置失敗,appid:&;.$this->authorizer_appid,$ret); return false; } } /* * 更新授權小程序的authorizer_access_token * @params string $appid : 小程序appid * @params string $refresh_token : 小程序authorizer_refresh_token * */ private function update_authorizer_access_token($appid,$refresh_token) { $url = 'https://api.weixin.qq.com/cgi-bin/component/api_authorizer_token?component_access_token=' . $this->thirdAccessToken; $data = '{&;component_appid&;:&;' . $this->thirdAppId . '&;,&;authorizer_appid&;:&;' . $appid . '&;,&;authorizer_refresh_token&;:&;' . $refresh_token . '&;}'; $ret = json_decode(https_post($url, $data)); if (isset($ret->authorizer_access_token)) { Db::name('wxminiprograms')->where(['authorizer_appid' => $appid])->update(['authorizer_access_token' => $ret->authorizer_access_token, 'authorizer_expires' => (time() + 7200), 'authorizer_refresh_token' => $ret->authorizer_refresh_token]); return $ret; } else { $this->errorLog(&;更新授權小程序的authorizer_access_token操作失敗,appid:&;.$appid,$ret); return null; } } private function errorLog($msg,$ret) { file_put_contents(ROOT_PATH . 'runtime/error/miniprogram.log', &;[&; . date('Y-m-d H:i:s') . &;] &;.$msg.&;,&; .json_encode($ret).PHP_EOL, FILE_APPEND); }}<?php//代小程序?qū)崿F(xiàn)業(yè)務示例包namespace app\user\controller;use app\home\model\Miniprogram;use think\Db;class Wxminiprogram extends Pub{ public $appid = 'wx57****1bfb'; //需要實現(xiàn)業(yè)務小程序appid public function index() { return view(); } public function doAction() { if(request()->isPost()) { $action = input('action'); $mini = new Miniprogram($this->appid); if($action == 'auth') { //小程序授權 echo '<script>alert(&;已授權&;);history.back();</script>'; } elseif($action == 'setServerDomain') { //設置小程序服務器域名地址 if($mini->setServerDomain()){ echo '<script>alert(&;設置小程序服務器域名操作成功&;);history.back();</script>'; } else { echo '<script>alert(&;設置小程序服務器域名操作失敗或已設置,請查看日志&;);history.back();</script>'; } } elseif($action == 'setBusinessDomain') { //設置業(yè)務域名 if($mini->setBusinessDomain()){ echo '<script>alert(&;設置小程序業(yè)務域名操作成功&;);history.back();</script>'; } else { echo '<script>alert(&;設置小程序業(yè)務域名操作失敗或已設置,請查看日志&;);history.back();</script>'; } } elseif($action == 'bind') { //綁定小程序體驗者 $wechatid = input('wechatid'); if($wechatid) { if($mini->bindMember($wechatid)){ echo '<script>alert(&;綁定小程序體驗者操作成功&;);history.back();</script>'; } else { echo '<script>alert(&;綁定小程序體驗者操作失敗,請查看日志&;);history.back();</script>'; } } else { echo '<script>alert(&;請輸入微信號&;);history.back();</script>'; } } elseif($action == 'uploadCode') { //上傳小程序代碼 if($mini->uploadCode(2)){ echo '<script>alert(&;上傳小程序代碼操作成功&;);history.back();</script>'; } else { echo '<script>alert(&;上傳小程序代碼操作失敗,請查看日志&;);history.back();</script>'; } } elseif($action == 'getExpVersion') { //獲取體驗小程序的體驗二維碼 $qrcode = $mini->getExpVersion(); if($qrcode){ echo '<script>window.location.href=&;'.$qrcode.'&;;</script>'; } else { echo '<script>alert(&;獲取體驗小程序的體驗二維碼操作失敗&;);history.back();</script>'; } } elseif($action == 'review') { //提交審核 $auditid = Db::name('wxminiprogram_audit')->where(['appid'=>$this->appid,'status'=>['neq'
'appid'=>$this->appid,'auditid'=>$auditid])->field('status,reason')->find(); if($audit['status'] == 0) { echo '<script>alert(&;該版本審核已通過&;);history.back();</script>'; } elseif($audit['status'] == 1) { echo '<script>alert(&;該版本審核失敗,原因:'.$audit['reason'].'&;);history.back();</script>'; } elseif($audit['status'] == 2) { echo '<script>alert(&;該版本小程序正在審核中......&;);history.back();</script>'; } else { echo '<script>alert(&;未知狀態(tài)......&;);history.back();</script>'; } } else { echo '<script>alert(&;查詢指定版本的審核狀態(tài)操作失敗,請查看日志&;);history.back();</script>'; } } else { echo '<script>alert(&;請輸入要查詢的審核ID&;);history.back();</script>'; } } elseif($action == 'lastAudit') { //查詢最新一次提交的審核狀態(tài) $auditid = $mini->getLastAudit(); if($auditid){ $audit = Db::name('wxminiprogram_audit')->where(['appid'=>$this->appid,'auditid'=>$auditid])->field('status,reason')->find(); if($audit['status'] == 0) { echo '<script>alert(&;審核已通過&;);history.back();</script>'; } elseif($audit['status'] == 1) { echo '<script>alert(&;審核失敗,原因:'.$audit['reason'].'&;);history.back();</script>'; } elseif($audit['status'] == 2) { echo '<script>alert(&;小程序正在審核中......&;);history.back();</script>'; } else { echo '<script>alert(&;未知狀態(tài)......&;);history.back();</script>'; } }else { echo '<script>alert(&;查詢最新一次提交的審核狀態(tài)操作失敗,請查看日志&;);history.back();</script>'; } } elseif($action == 'release') { //發(fā)布已通過審核的小程序 $auditid = Db::name('wxminiprogram_audit')->where(['appid'=>$this->appid,'status'=>['neq'x
相關建議:
開發(fā)微信微信官方賬號平臺視頻教程
微信公眾平臺開發(fā)者文檔
以上關于微信公眾平臺開發(fā)的視頻教程終于整理出來了。微信第三方平臺授權小程序業(yè)務詳情請多關注主機參考其他相關文章!
這幾篇文章你可能也喜歡:
- 您確定該服務是否破壞了? 使用Zabbix5電子郵件警報(Zabbix電子郵件警報原理)
- 在Tea Restaurant Mini計劃開始一個月后,雙重表演的秘訣是揭示的! (茶餐廳用餐)
- 如何使用迷你程序開發(fā)來增強移動應用程序(實施視頻程序功能)
- 為什么選擇Wydian迷你計劃來開始您的電子商務業(yè)務? (您為什么不能在Waidian上搜索迷你程序?)
- 如何制定一個微信微信計劃的優(yōu)勢是什么?
本文由主機參考刊發(fā),轉(zhuǎn)載請注明:最后整理了一下,小程序業(yè)務由微信第三方平臺授權(微信小程序授權方式)。 http://www.k2270.com/80014.html
主機參考

















評論前必須登錄!
注冊