VPS参考测评推荐
专注分享VPS主机优惠信息
衡天云优惠活动
华纳云最新优惠促销活动
jtti最新优惠促销活动
新罗云最新优惠促销活动

最后整理了一下,小程序业务由微信第三方平台授权(微信小程序授权方式)。

locvps
主机参考:VPS测评参考推荐/专注分享VPS服务器优惠信息!若您是商家可以在本站进行投稿,查看详情!此外我们还提供软文收录、PayPal代付、广告赞助等服务,查看详情!
我们发布的部分优惠活动文章可能存在时效性,购买时建议在本站搜索商家名称可查看相关文章充分了解该商家!若非中文页面可使用Edge浏览器同步翻译!PayPal代付/收录合作

这篇文章是我自己写的,是微信第三方平台开发实现的。代码完整,每一步都有详细介绍,供大家参考。

第一步:申请微信开放平台账号,创建第三方平台。

最后整理了一下,小程序业务由微信第三方平台授权(微信小程序授权方式)。-主机参考

最后整理了一下,小程序业务由微信第三方平台授权(微信小程序授权方式)。-主机参考

最后整理了一下,小程序业务由微信第三方平台授权(微信小程序授权方式)。-主机参考

最后整理了一下,小程序业务由微信第三方平台授权(微信小程序授权方式)。-主机参考

第二步:微信官方账号/小程序授权给第三方平台。

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用于获取第三方平台接口调用凭证。/* *代码扫描授权。注意,这个网址必须放在页面中间,用户不能跳转程序。否则,“请确认授权门户页面所在的域名,与授权后回调页面的域名相同......”错误* @ paramstring $ redirect _ uri:扫码成功后回调地址* @ paramint $ auth _ type:授权类型,1个微信官方账号,2个小程序,3个微信官方账号/小程序同时显示。默认情况下,所有未传递的参数都显示*/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 *注意这个值要保存,但是这里不保存代码*/私有函数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 */私有函数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;错误代码;}}/* *发起POST网络提交* @params string $url:网络地址* @ params JSON $ data:JSON格式数据发送*/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网络提交* @ 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,FALSE);curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,FALSE);curl_setopt($curl,CURLOPT_HEADER,FALSE);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用于获取第三方平台接口调用凭证。/* *接收微信官方推送的消息(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警报( 对于要处理的版本,请在发布该版本之前处理好该版本的相关事宜。审计id: # 39;。$auditid。'");history . back(); lt/script gt;';} else { $ errcode = $ mini - gt;发布();if($ errcode){ echo # 39; lt脚本 gt警报( 发行版”);history . back(); lt/script gt;';} else { echo # 39 lt脚本 gt警报( 发布失败,错误代码: # 39;。$errcode。'");history . back(); lt/script gt;';}}}}}基本上就是通过这两个价值来实现小程序代工商

-- Adminer 4.6.2 MySQL转储集名称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;平台产生的代币价值 # 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;二维码的网址 # 39;,` business_info` varchar(255)默认空注释 # 39;Json格式。用于了解以下功能的开启状态(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格式。是否被小程序类型授权,包括网络小程序设置的各个服务器的域名 # 39;,` func _ info` longtext COMMENT # 39Json格式。权限列表,ID号17到19分别代表:17。账户管理权限18。开发管理许可。客户服务消息管理权限。请注意:1)该字段的返回不会考虑小程序是否有该权限集的权限(因为其中部分可能有)。',` authorizer_appid` varchar(45)默认空注释 # 39;Applet appid # 39,` authorizer _ access _ token ` varchar(255)默认空注释 # 39;授权方接口调用凭证(该返回值仅在被授权的微信官方账号或小程序有API权限时可用),简称token # 39;,` authorizer _ expires ` int(10)unsigned默认空注释 # 39;刷新的有效期 # 39;,` authorizer _ refresh _ token ' varchar(255)默认空注释 # 39;调用接口凭证刷新令牌 # 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数据表,保存提交审核的小程序

-- Adminer 4.6.2 MySQL转储集名称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;审批状态,其中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/** 代小程序实现业务*/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 : 域名地址。只接收一维数组。 * */ 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; } } /* * 设置小程序业务域名,无需加https前缀,但域名必须可以通过https访问 * @params string / array $domains : 域名地址。只接收一维数组。 * */ 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(&;设置小程序业务域名失败,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 : 指定体验版二维码跳转到某个具体页面 * */ 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 微信投票 微网站 微信商城&; ,$title = &;魔盒CMS微信公众号营销小程序开发&;) { $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; } } /* * 小程序审核撤回 * 单个帐号每天审核撤回次数最多不超过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(&;小程序审核撤回操作失败,appid:&;.$this->authorizer_appid,$ret); return false; } } /* * 查询指定版本的审核状态 * @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(&;查询指定版本的审核状态操作失败,appid:&;.$this->authorizer_appid,$ret); return false; } } /* * 查询最新一次提交的审核状态 * */ 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(&;查询最新一次提交的审核状态操作失败,appid:&;.$this->authorizer_appid,$ret); return false; } } /* * 发布已通过审核的小程序 * */ 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(&;发布已通过审核的小程序操作失败,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//代小程序实现业务示例包namespace app\user\controller;use app\home\model\Miniprogram;use think\Db;class Wxminiprogram extends Pub{ public $appid = 'wx57****1bfb'; //需要实现业务小程序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') { //设置业务域名 if($mini->setBusinessDomain()){ echo '<script>alert(&;设置小程序业务域名操作成功&;);history.back();</script>'; } else { echo '<script>alert(&;设置小程序业务域名操作失败或已设置,请查看日志&;);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(&;未知状态......&;);history.back();</script>'; } } else { echo '<script>alert(&;查询指定版本的审核状态操作失败,请查看日志&;);history.back();</script>'; } } else { echo '<script>alert(&;请输入要查询的审核ID&;);history.back();</script>'; } } elseif($action == 'lastAudit') { //查询最新一次提交的审核状态 $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(&;未知状态......&;);history.back();</script>'; } }else { echo '<script>alert(&;查询最新一次提交的审核状态操作失败,请查看日志&;);history.back();</script>'; } } elseif($action == 'release') { //发布已通过审核的小程序 $auditid = Db::name('wxminiprogram_audit')->where(['appid'=>$this->appid,'status'=>['neq'x

相关建议:

开发微信微信官方账号平台视频教程

微信公众平台开发者文档

以上关于微信公众平台开发的视频教程终于整理出来了。微信第三方平台授权小程序业务详情请多关注主机参考其他相关文章!

这几篇文章你可能也喜欢:

本文由主机参考刊发,转载请注明:最后整理了一下,小程序业务由微信第三方平台授权(微信小程序授权方式)。 https://zhujicankao.com/80014.html

【腾讯云】领8888元采购礼包,抢爆款云服务器 每月 9元起,个人开发者加享折上折!
打赏
转载请注明原文链接:主机参考 » 最后整理了一下,小程序业务由微信第三方平台授权(微信小程序授权方式)。
主机参考仅做资料收集,不对商家任何信息及交易做信用担保,购买前请注意风险,有交易纠纷请自行解决!请查阅:特别声明

评论 抢沙发

评论前必须登录!