In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
In this article, the editor introduces in detail "how to develop Wechat third-party Mini Program". The content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to develop Wechat third-party Mini Program" can help you solve your doubts. Let's follow the editor's train of thought to slowly deepen, together to learn new knowledge.
Note: if the error code is returned during debugging, please check the mini program development api page.
The domain name used by Mini Program developer is the domain name that you filled in when you applied for a third party.
There are only a maximum of 50 Mini Program code templates, which can be deleted and re-added.
Preparatory work:
Apply for the third party of Wechat and the authority there should choose the previous generation development, after the third party application is successful, it is to prepare Mini Program, need two Mini Program, one as Mini Program code base, one as a user trial, need to be authorized in the third party.
Add Mini Program code base: add Mini Program as a development Mini Program in a third party, and then the Mini Program becomes a third-party development Mini Program, and then all the code submitted by the Mini Program will be stored in the third-party draft box. you can choose the version to add as a template, a third party can only have up to 50 templates.
Generation development process:
Post requests a public method to interact with the Wechat server
The code is as follows
Protected function curl_post ($curlHttp, $postdata) {$ch = curl_init (); / send data to api curl_setopt ($ch, CURLOPT_POST, true) using curl; curl_setopt ($ch, CURLOPT_POST, true); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt ($ch, CURLOPT_URL, $curlHttp); curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE) Curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, FALSE); $response = curl_exec ($ch); curl_close ($ch); $result = json_decode ($response, true); return $result;}
Get requests a public method to interact with the Wechat server
The code is as follows
Protected function buildRequestForm (array $param, $method, $target='',$jump=false) {$sHtml = "; if (! empty ($param)) {foreach ($param as $key = > $value) {$sHtml.=";}} $sHtml.= ""; if ($jump) $sHtml = $sHtml. "document.getElementById (\" autoSubmit\ "). Submit ();"; return $sHtml;}
Get the authorizer api to call the flattening access_token public method
The code is as follows
Protectd function getAccessToken ($appId) {$accessToken ='; if (empty ($appId)) {return $accessToken;} / / the logic in the middle fills in return $accessToken;}
First, develop a set of Mini Program and upload it, and then set the version as a template in a third party. In this case, you use the template id (for code specification).
Assign the Mini Program code to the user Mini Program by calling the API Wechat
The code is as follows
Public function commitCode () {$appId = input ('app_id','); $descript = input ('descript',' test code specified'); $version = input ('version',' V.1.0'); $templateId = input ('template_id', 1); if (empty ($appId)) {$this- > error (appid cannot be empty); return } if (empty ($templateId) & & ($templateId! = 0)) {$this- > error ('template id cannot be empty'); return;} $accessToken = $this- > getAccessToken ($appId) / / I erased my personal information. Please add $extJson = array ('extAppid' = > $appId,' ext' = > array ('attr1' = >' value1'), 'extPages' = > array (' pages/index/index' = > array ('navigationBarTitleText' = >'') in the empty character part. 'pages/media/media' = > array (' navigationBarTitleText' = >'), 'pages' = > array (' pages/index/index', 'pages/media/media'),' window' = > array ('backgroundColor' = >' # f8f8f8f8), 'navigationBarTextStyle' = >' white', "navigationBarTitleText" = > "" 'navigationBarBackgroundColor' = >' # 2b3b48'), 'tabBar' = > array (' list' = > array (array ('text' = >'', 'pagePath' = >' pages/index/index',), array ('text' = >', 'pagePath' = >' pages/media/media') ), 'networkTimeout' = > array (' request' = > 10000, 'uploadFile' = > 10000,' downloadFile' = > 10000, 'connectSocket' = > 10000)) $params = array ('template_id' = > $templateId,' user_version' = > $version, 'user_desc' = > $descript,' ext_json' = > json_encode ($extJson, JSON_UNESCAPED_UNICODE)); $result = $this- > curl_post ('https://api.weixin.qq.com/wxa/commit?access_token='.$accessToken, json_encode ($params, JSON_UNESCAPED_UNICODE)) If (empty ($result) | |! empty ($result ['errcode'])) {$this- > error (' code specification error'); return;} $this- > success ('operation successful'); return;}
After specifying the code, you will check whether the function is normal, so you have to call Wechat API to get the experience of scanning QR code.
The code is as follows
Public function getExpCode () {$appId = input ('app_id','); if (empty ($appId)) {$this- > error (appid cannot be empty); return;} $accessToken = $this- > getAccessToken ($appId); if (empty ($accessToken)) {$this- > error ('obtain accessToken error'); return;} $params = array ('access_token' = > $accessToken) $result = $this- > buildRequestForm ($params, 'GET',' https://api.weixin.qq.com/wxa/get_qrcode?access_token='.$accessToken, true); echo $result; exit;}
If the authorized user does not have the experience permission, then the Mini Program function cannot be experienced after scanning the code. At this time, you need to set the user as the experiencer through the Wechat interface. This step can be performed in the user management of the Mini Program platform. In order to improve the precision, you can add and delete the experiencer through the Wechat API. When adding, you need to be confirmed by the user Wechat.
The code is as follows
Public function bindTester () {$appId = input ('app_id',''); $wxNumber = input ('wx_number','); if (empty ($appId)) {$this- > error (appid cannot be empty); return;} if (empty ($wxNumber)) {$this- > error (Wechat number cannot be empty); return;} $accessToken = $this- > getAccessToken ($appId) If (empty ($accessToken)) {$this- > error ('license accessToken error'); return;} $params = array ('wechatid' = > $wxNumber); $result = $this- > curl_post (' https://api.weixin.qq.com/wxa/bind_tester?access_token='.$accessToken, json_encode ($params)); print_r ($result); exit; return } public function unBindTester () {$appId = input ('app_id',''); $wxNumber = input ('wx_number','); if (empty ($appId)) {$this- > error (appid cannot be empty); return;} if (empty ($wxNumber)) {$this- > error (Wechat number cannot be empty); return;} $accessToken = $this- > getAccessToken ($appId) If (empty ($accessToken)) {$this- > error ('license accessToken error'); return;} $params = array ('wechatid' = > $wxNumber); $result = $this- > curl_post (' https://api.weixin.qq.com/wxa/unbind_tester?access_token='.$accessToken, json_encode ($params)); print_r ($result); exit; return;}
If there is a problem with the experience feature, re-adjust the Mini Program code logic and set it as a template after uploading. If there is no problem, submit the Mini Program code for review, but you need to specify category when submitting it for review, so you need to call Wechat API to view it.
If the authorized user is not set up, you need the other party to enter the Mini Program platform and add a service entry at the place where the Mini Program information is entered.
The code is as follows
Public function getCategory () {$appId = input ('app_id','); if (empty ($appId)) {$this- > error (appid cannot be empty); return;} $accessToken = $this- > getAccessToken ($appId); if (empty ($accessToken)) {$this- > error ('obtain accessToken error'); return;} $params = array ('access_token' = > $accessToken) $result = $this- > buildRequestForm ($params, 'GET',' https://api.weixin.qq.com/wxa/get_category?access_token='.$accessToken, true); echo $result; exit;}
After getting the service entry, you will submit the code for review.
The code is as follows
Public function submitAudit () {$appId = input ('app_id','); if (empty ($appId)) {$this- > error (appid cannot be empty); return;} $accessToken = $this- > getAccessToken ($appId); if (empty ($accessToken)) {$this- > error ('get license accessToken error'); return } $params = array ('item_list' = > array (' address' = > 'pages/index/index',' tag' = >'IT Technology', 'first_class' = >' IT Technology', 'second_class' = >' hardware and equipment', 'title' = >' generate QR Code') Array ('address' = >' pages/media/media', 'tag' = >' tools', 'first_class' = >' tools', 'second_class' = >' office', 'title' = >' multimedia upload') $result = $this- > curl_post ('https://api.weixin.qq.com/wxa/submit_audit?access_token='.$accessToken, json_encode ($params, JSON_UNESCAPED_UNICODE)); echo''; print_r ($result); exit; $this- > success (' successful operation'); return;}
After submitting the audit, the Wechat server will return an audit id, through which you can query the audit status id.
After the approval is passed, Wechat will push an audit result to your callback address registered by a third party.
The code is as follows
Public function getAuditStatus () {$appId = input ('app_id','); if (empty ($appId)) {$this- > error (appid cannot be empty); return;} $accessToken = $this- > getAccessToken ($appId); if (empty ($accessToken)) {$this- > error ('obtain accessToken error'); return;} $params = array ('auditid' = > 12334) $result = $this- > curl_post ('https://api.weixin.qq.com/wxa/get_auditstatus?access_token='.$accessToken, json_encode ($params)); print_r ($result); exit; return;}
When Mini Program is approved, then Mini Program is released.
The code is as follows
Public function release () {$appId = input ('app_id','); if (empty ($appId)) {$this- > error (appid cannot be empty); return;} $accessToken = $this- > getAccessToken ($appId); if (empty ($accessToken)) {$this- > error ('get license accessToken error'); return } $result = $this- > curl_post ('https://api.weixin.qq.com/wxa/release?access_token='.$accessToken,' {}'); print_r ($result); exit; return } after reading this, the article "how to develop Wechat third-Party Mini Program" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it yourself to understand it. If you want to know more about related articles, welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.