If there are multiple businesses and the same public number/small program with the same function mode, if only small program development, it is not necessary to copy multiple sets of code, change the APPID information, in the background of wechat public number, configure domain name server and key and other tedious information, each change a submission and release, repeat the steps. With the gradual increase in the number of public/small programs to maintain, the need to invest in resources and costs also increase.

Have you ever thought, just need to develop a set of public number/small program code, as a template, and then a set of background management system, the wechat public number do those things in the background are moved to our own system. To a small program with the same business, only need the administrator authorization, as long as a few buttons in our system, you can put the small program released online, a development for N public use, to provide standardized interface services to meet the basic needs of the business. By scanning the TWO-DIMENSIONAL code to authorize the platform, to help N more than one public account generation to achieve business, no longer need to understand the tedious parameter Settings, and the password is not provided to the developers, to ensure security, truly free the hands of the operation of the students and the development of the hands, there is more time to talk about the girlfriend, that would be good. Yes, wechat third-party platform development is to help you save more time to meet women.

An overview of the

Wechat Public Platform – Third-party platform (third-party platform for short) is open to all developers who have passed the developer qualification certification. In the public or small program operators (operators), after the authorization of the third party platform developers can by calling WeChat open platform interface ability, for the public, or small program operators to provide account application, small programs to create, technology development, industry solutions, event marketing, plug-in ability and other comprehensive services. The operator of the same account can choose multiple suitable third parties to provide product capabilities or entrust operation.

In terms of business characteristics, a third-party platform must look like this:In terms of service scenarios, third-party platforms include the following scenarios:

Provide industry solutions, such as e-commerce industry solutions, or tourism industry solutions;

Industry :(horizontal) to provide more professional operation ability, fine operation user public number or small program;

Functions :(vertical) the optimization of the functions of the public platform, such as the tool specially optimized for the visual style and typesetting of text messages, or the customized CRM user management function, or the powerful small program plug-in, etc.

The prerequisite to access third-party development is to have wechat open platform applications. Please refer to the detailed creation steps

Developers.weixin.qq.com/doc/oplatfo… 1. Obtain the verification ticket

Verification Ticket (Component_verify_ticket). After a third-party platform is created and approved, the wechat server sends component_Verify_ticket to the URL for receiving Authorized Events every 10 minutes in POST mode

Upon receiving the POST request, you simply return the string SUCCESS directly. To enhance security, the XML in PostData is encrypted using the encryption and decryption key used at the time of the service request and decrypted after the push is received.

public void saveTicket(HttpServletRequest request, HttpServletResponse response) throws IOException { String msgSignature = request.getParameter("msg_signature"); String timeStamp = request.getparameter (" timeStamp "); // Timestamp String nonce = request.getParameter("nonce"); // random number BufferedReader br = new InputStreamReader(new inputStream (request.getinputStream ()," utF-8 ")); StringBuffer sb = new StringBuffer(); String line = null; while ((line = br.readLine()) ! = null) { sb = sb.append(line); } String postData = sb.toString(); try { AuthorizedUtils.saveComponentVerifyTicket(msgSignature, timeStamp, nonce, postData); } catch (Exception e) {logger.error(" system Exception ", e); PrintWriter out = response.getwriter (); out.print("success"); }}Copy the code

2. Get the token

A token (Component_Access_token) is the invocation credential of a third-party platform interface. The token acquisition is limited. Each token is valid for 2 hours. Please manage the token by yourself.

public static ComponentToken getComponentToken(String ticket) { RedisService<ComponentToken> redisService = RedisService.load(); ComponentToken componentToken = redisService.load(ComponentToken.COMPONENTTOKEN_ID, ComponentToken.class); if (componentToken == null) { String encryptAppId = ThirdPlat.PLAT_APPID; String appId = EnDecryptUtil.d3esDecode(encryptAppId); String encryptSecret = ThirdPlat.PLAT_SECRET; String secret = EnDecryptUtil.d3esDecode(encryptSecret); String requestUrl = AuthAccessUrl.COMPONENT_ACCESS_URL; Map<String, String> map = new HashMap<>(); map.put("component_appid", appId); // AppId map.put("component_appsecret", secret); // Third-party platform AppSecret map.put("component_verify_ticket", ticket); // Third-party platform AppSecret map.put("component_verify_ticket", ticket); String outputStr = JSONObject.toJSONString(map); Logger.warn (" Request data "+outputStr); logger.warn(" Request data "+outputStr); JSONObject jsonObject = HttpRequestUtils.httpRequest(requestUrl, "POST", outputStr); if (null ! = jsonObject) { long expires = System.currentTimeMillis() + 7200; try{ expires = System.currentTimeMillis() + jsonObject.getIntValue("expires_in"); }catch (Exception e) { } try { componentToken = new ComponentToken(); componentToken.setComponentAccessToken(jsonObject.getString("component_access_token")); componentToken.setExpiresIn(expires); redisService.save(componentToken, ComponentToken.class); } catch (Exception e) { componentToken = null; Logger. error(" system exception ", e); } } } else { long sysTime = System.currentTimeMillis(); if (sysTime >= componentToken.getExpiresIn()) { redisService.delete(ComponentToken.COMPONENTTOKEN_ID, ComponentToken.class); componentToken = getComponentToken(ticket); }else{ } } return componentToken; }Copy the code

3. Create small programs quickly

The rapid creation of small program interface optimizes the process of small program registration and certification, which can help third-party platforms rapidly expand offline merchants, expand the service scope of merchants, and seize the initiative of small program offline business. The legal person face recognition method to replace the authentication process such as small payment, greatly reducing the labor cost of the collection of small program subject, category qualification information. The third-party platform only needs to collect the corporate name, corporate wechat, corporate name, corporate code information of the four information, then can send a template message to the corporate face information collection, complete the registration, authentication process. And when the legal entity receives the APPID of the mini-program successfully created, it sends a template message to the legal entity at the same time, prompting the legal entity to set the mailbox and password, so that the legal entity can log in the mini-program console for subsequent management.

The default value for creating applets through this interface is Authenticated. In order to reduce the cost threshold of accessing applets, applets created through this interface do not need to pay 300 yuan authentication fee.

public AjaxResult fastRegister(String merchantId) { Merchant merchant = merchantService.getById(merchantId); If (merchant == null) {logger.warn(" quick create small program ----> failed, merchant is null"); Return ajaxresult. error(" failed to create applet quickly, merchant is null",null); } else { RedisService<ComponentVerifyTicket> redisService = RedisService.load(); ComponentVerifyTicket componentVerifyTicket = redisService.load(ComponentVerifyTicket.COMPONENT_VERIFY_TICKET_ID, ComponentVerifyTicket.class); If (componentVerifyTicket == null) {logger.warn(" quick create widget ----> failed, component_verify_ticket is null"); Return ajaxresult. error(" failed to create applet quickly, component_verify_ticket is null",null); } else { ComponentToken componentToken = AuthorizedUtils.getComponentToken(componentVerifyTicket.getComponentVerifyTicket()); RegisterWeappOut out = new RegisterWeappOut(); out.setName(merchant.getName()) .setCode(merchant.getCode()) .setCode_type(merchant.getCodeType()) .setLegal_persona_wechat(merchant.getLegalPersonaWechat()) .setLegal_persona_name(merchant.getLegalPersonaName()) .setComponent_phone(merchant.getComponentPhone()); JSONObject obj = BaseUtils.createRegisterWeapp(componentToken,out); if (obj.getInteger("errcode") == 0 && "ok".equalsIgnoreCase(obj.getString("errmsg"))) { return AjaxResult.success(); } else { return AjaxResult.error(obj.getInteger("errcode"),obj.getString("errmsg")); }}}}Copy the code

4. Obtain the pre-authorization code

The pre_AUTH_code is required for third-party platforms to implement authorization hosting. Each pre_auth_code is valid for 10 minutes. You need to get a token to call.

public static String getPreAuthCode(String ticket) {
ComponentToken componentToken = getComponentToken(ticket);
String encryptAppId = ThirdPlat.PLAT_APPID;
String appId = EnDecryptUtil.d3esDecode(encryptAppId);
String url = AuthAccessUrl.PRE_AUTH_CODE_URL + componentToken.getComponentAccessToken();
Map<String, String> map = new HashMap<String, String>();
map.put("component_appid", appId);
    JSONObject jsonObject = HttpRequestUtils.httpRequest(url, "POST", JSONObject.toJSONString(map));   
return jsonObject.getString("pre_auth_code");
}
Copy the code

5. Guide merchants to obtain authorization information

The third-party service provider constructs an authorization link to place its own website. After the user clicks, the authorization page pops up.

public AjaxResult getMchWebAuthUrl(@PathVariable("id") String id) { RedisService<ComponentVerifyTicket> redisService = RedisService.load(); ComponentVerifyTicket componentVerifyTicket = redisService.load(ComponentVerifyTicket.COMPONENT_VERIFY_TICKET_ID, ComponentVerifyTicket.class); If (componentVerifyTicket == NULL){return ajaxresult. error(" Failed to import user to authorization page, COMPONent_verify_ticket is null",null); }else{ String preAuthCode = AuthorizedUtils.getPreAuthCode(componentVerifyTicket.getComponentVerifyTicket()); String encryptAppId = ThirdPlat.PLAT_APPID; String appId = EnDecryptUtil.d3esDecode(encryptAppId); String auth_type = ThirdPlat.AUTH_TYPE; String requestUrl = AuthAccessUrl.WEB_AUTH_URL; try { requestUrl = requestUrl.replace("COMPONENT_APPID", appId).replace("PRE_AUTH_CODE", preAuthCode) .replace("REDIRECT_URI", URLEncoder.encode(ThirdPlat.REDIRECT_URI.replace("MERCHANTID", id),"UTF-8")).replace("AUTH_TYPE", auth_type); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } logger.warn(" Step 2: import user to authorization page ----> success, url: "+ requestUrl); Return ajaxresult. success(" operation succeeded ",requestUrl); }}Copy the code

6. Set the basic information of the applet

Set the name of the small program, when the name does not match the keyword, it is directly set successfully; When the name matches the keyword, the certification materials should be submitted and reviewed. Modify the avatar of the applet. Modified Function description. Modify applets privacy Settings, that is, to make them searchable.

public AjaxResult setBasicInfo(BasicInfo basicInfo) throws IOException { Merchant merchant = merchantService.getById(basicInfo.getMerchantId()); If (merchant == null) {logger.warn(" merchant = null"); Return ajaxresult. error(" Merchant is null, merchant is null",null); } else { AuthorizationInfo info = AuthorizedUtils.getAuthorizationInfo(merchant.getAppid()); If (stringutils.isnotempty (basicinfo.getheadimage ())) {UploadIn uli = new UploadIn(); uli.setType("image").setUrlPath(basicInfo.getHeadImage()); JSONObject uploadJson = BaseUtils.upload(info,uli); String mediaId = uploadJson.getString("media_id"); ModifyHeadImageIn mhi = new ModifyHeadImageIn(); mhi.setHead_img_media_id(mediaId).setX1("0").setY1("0").setX2("1").setY2("1"); JSONObject obj = BaseUtils.modifyHeadImage(info,mhi); if (! obj.getInteger(ResStatus.ERRCODE).equals(ResStatus.CODE) || ! ResStatus.MSG.equalsIgnoreCase(obj.getString(ResStatus.ERRMSG))) { return AjaxResult.error(obj.getInteger(ResStatus.ERRCODE),obj.getString(ResStatus.ERRMSG)); } else { merchant.setAppletsHeadImg(basicInfo.getHeadImage()); If (stringutils.isnotempty (basicinfo.getnickName ())) {UploadIn uli = new UploadIn(); uli.setType("image").setUrlPath(merchant.getBusinessLicense()); JSONObject uploadJson = BaseUtils.upload(info,uli); String mediaId = uploadJson.getString("media_id"); SetNicknameIn sni = new SetNicknameIn(); sni.setNick_name(basicInfo.getNickname()); sni.setLicense(mediaId); JSONObject obj = BaseUtils.setNickname(info,sni); if (! obj.getInteger(ResStatus.ERRCODE).equals(ResStatus.CODE) || ! ResStatus.MSG.equalsIgnoreCase(obj.getString(ResStatus.ERRMSG))) { return AjaxResult.error(obj.getInteger(ResStatus.ERRCODE),obj.getString(ResStatus.ERRMSG)); } else { merchant.setAppletsName(basicInfo.getNickname()); if (obj.containsKey("audit_id") && StringUtils.isNotEmpty(obj.getString("audit_id"))) { merchant.setAuditId(obj.getString("audit_id")); If (stringutils.isnotempty (basicInfo.getSignature())) {ModifySignatureIn mSI = new ModifySignatureIn(); msi.setSignature(basicInfo.getSignature()); JSONObject obj = BaseUtils.modifySignature(info, msi); if (! obj.getInteger(ResStatus.ERRCODE).equals(ResStatus.CODE) || ! ResStatus.MSG.equalsIgnoreCase(obj.getString(ResStatus.ERRMSG))) { return AjaxResult.error(obj.getInteger(ResStatus.ERRCODE),obj.getString(ResStatus.ERRMSG)); } else { merchant.setAppletsSignature(basicInfo.getSignature()); If (stringutils.isnotempty (basicInfo.getStatus()))) {SearchStatusIn ssi = new SearchStatusIn(); ssi.setStatus(basicInfo.getStatus()); JSONObject obj = BaseUtils.changeWxaSearchStatus(info, ssi); if (! obj.getInteger(ResStatus.ERRCODE).equals(ResStatus.CODE) || ! ResStatus.MSG.equalsIgnoreCase(obj.getString(ResStatus.ERRMSG))) { return AjaxResult.error(obj.getInteger(ResStatus.ERRCODE),obj.getString(ResStatus.ERRMSG)); } else { merchant.setSearchStatus(basicInfo.getStatus()); } } merchantService.updateById(merchant); return AjaxResult.success(); }}Copy the code

7. Payment authorization

Enter the merchant number and key, and upload the P12 certificate 8. Set the server domain name

Authorization to a third party program, the server domain name only can server for third-party platform, when the program through a third party after the release code online platform, small program their original configuration server domain name will be removed, only keep the third party platform of the domain name, so the third party platform before release instead of a small program code, Need to call the interface for the applets to add the third party platform’s own domain name.

Note:

You need to register the domain name in the applets server domain name of a third-party platform before invoking the interface for configuration.

A maximum of 1000 valid server domain names can be added. A maximum of 200 Request, Socket, Uploadfile, Download, and Udp domain names are supported.

You can submit 50 modification requests per month.

public AjaxResult modifyDomain(ModifyDomain modifyDomain) { Merchant merchant = merchantService.getById(modifyDomain.getMerchantId()); If (merchant == null) {logger.warn(" set server domain ----> failed, merchant null"); Return ajaxresult. error(" merchant is null, merchant is null",null); } else { AuthorizationInfo info = AuthorizedUtils.getAuthorizationInfo(merchant.getAppid()); ModifyDomainOut out = new ModifyDomainOut(); out.setAction(modifyDomain.getAction()); String[] requests = modifyDomain.getRequestdomain().split(","); List<String> requestList = Arrays.asList(requests); out.setRequestdomain(requestList); String[] wsrequests = modifyDomain.getWsrequestdomain().split(","); List<String> wsrequestList = Arrays.asList(wsrequests); out.setWsrequestdomain(wsrequestList); String[] uploads = modifyDomain.getUploaddomain().split(","); List<String> uploadList = Arrays.asList(uploads); out.setUploaddomain(uploadList); String[] downloads = modifyDomain.getDownloaddomain().split(","); List<String> downloadsList = Arrays.asList(downloads); out.setDownloaddomain(downloadsList); JSONObject obj = BaseUtils.modifyDomain(info, out); if("0".equals(obj.getString("errcode")) && "ok".equalsIgnoreCase(obj.getString("errmsg"))){ return AjaxResult.success();  } else { return AjaxResult.error(obj.getInteger("errcode"),obj.getString("errmsg")); }}}Copy the code

9. Set the service domain name

Authorization to a third party of small procedures, the business domain name only can server for third-party platform, when the program through a third party after the release code online, small program their original configuration business domain name will be removed, only keep the third party platform of the domain name, so the third party platform in before code instead of a small program, you need to call interface for the small program to add the business domain.

Note:

You need to register the service domain name in the applets service domain name of the third-party platform before invoking the interface for configuration.

You can configure a subdomain name for an authorized applet. For example, if the service domain name registered by a third party is QQ.com, you can add QQ.com and its subdomain name (such as XXX.qq.com) to the authorized applet.

A maximum of 100 service domain names can be added.

public AjaxResult webviewDomain(WebviewDomain webviewDomain) { Merchant merchant = merchantService.getById(webviewDomain.getMerchantId()); If (merchant == null) {logger.warn(" merchant = null"); Return ajaxresult. error(" failed to set business domain name, merchant is null",null); } else { AuthorizationInfo info = AuthorizedUtils.getAuthorizationInfo(merchant.getAppid()); SetWebViewDomainOut out = new SetWebViewDomainOut(); out.setAction(webviewDomain.getAction()); String[] webviews = webviewDomain.getWebviewdomain().split(","); List<String> webviewList = Arrays.asList(webviews); out.setWebviewdomain(webviewList); JSONObject obj = BaseUtils.setWebViewDomain(info, out); if("0".equals(obj.getString("errcode")) && "ok".equalsIgnoreCase(obj.getString("errmsg"))){ return AjaxResult.success();  } else { return AjaxResult.error(obj.getInteger("errcode"),obj.getString("errmsg")); }}}Copy the code

10, upload small program code

For third-party platforms, you need to add the draft to the code template library, or select a code template from the code template library and obtain the corresponding template ID (template_id). This interface can then be called to upload code for authorized applets.

public AjaxResult commit(CommitModel model) { Merchant merchant = merchantService.selectMerchantById(model.getMerchantId()); If (merchant == null) {logger.warn(" upload code ----> failed, merchant is null"); Return ajaxresult. error(" upload code, merchant is null",null); } AuthorizationInfo info = AuthorizedUtils.getAuthorizationInfo(merchant.getAppid()); CommitIn commitIn = new CommitIn(); String value = model.getValue(); String[] items = value.split("_"); String version = items[2]; commitIn.setTemplate_id(items[0]) .setUser_desc(items[1]) .setUser_version(version); JSONObject obj = new JSONObject(); obj.put("extAppid", merchant.getAppid()); Map<String, Object> map = new HashMap<>(); map.put("merchantId", model.getMerchantId()); map.put("userVersion", commitIn.getUser_version()); obj.put("ext", map); map = new HashMap<>(); Map<String, Object> maps = new HashMap<>(); maps.put("pages/index/index", map); obj.put("extPages", maps); commitIn.setExt_json(JSONObject.toJSONString(obj)); Obj = CodeUtils.com MIT (info, commitIn); if("0".equals(obj.getString("errcode")) && "ok".equalsIgnoreCase(obj.getString("errmsg"))){ AppletsRelease ar = appletsReleaseService.getOne(new LambdaQueryWrapper<AppletsRelease>() .eq(AppletsRelease::getMerchantId,merchant.getId())); if(ar == null){ ar = new AppletsRelease(); ar.setMerchantId(model.getMerchantId()).setHistoryversion(version); } else{ ar.setHistoryversion(version); } appletsReleaseService.saveOrUpdate(ar); return AjaxResult.success(); } else { return AjaxResult.error(obj.getInteger("errcode"),obj.getString("errmsg")); }}Copy the code

11. Member management

Before the third-party platform helps its authorized small program to submit code review, it can first let the small program operator experience, and before experience, the operator’s personal wechat signal needs to be added to the list of the small program experiential.

Note: If the operator is also the administrator of this small program, there is no need to bind, and the administrator has the experience permission by default.

/** * bindTester * @parambindtester * @return */ @override public AjaxResult bindTester(bindTester bindTester) {Merchant merchant = merchantService.getById(bindTester.getMerchantId()); If (merchant == null) {logger.warn(" merchant is null"); Return ajaxresult. error(" merchant is null, merchant is null",null); } else { AuthorizationInfo info = AuthorizedUtils.getAuthorizationInfo(merchant.getAppid()); JSONObject obj = MemberUtils.bindTester(info, bindTester.getWechatId()); if("0".equals(obj.getString("errcode")) && "ok".equalsIgnoreCase(obj.getString("errmsg"))){ AppletsTester at = new AppletsTester(); at.setMerchantId(bindTester.getMerchantId()).setWechatId(bindTester.getWechatId()).setUserStr(obj.getString("userstr"));  appletsTesterService.insertAppletsTester(at); return AjaxResult.success(); } else { return AjaxResult.error(obj.getInteger("errcode"),obj.getString("errmsg")); }} /** * Override public AjaxResult unbindTester(Long[] testerIds) {for (Long) id : testerIds) { AppletsTester tester = appletsTesterService.getById(id); If (Tester == null) {logger.warn(" untester ----> failed, Tester is null"); Return ajaxresult. error(" Remove tester, tester is null",null); } Merchant merchant = merchantService.getById(tester.getMerchantId()); If (merchant == null) {logger.warn(" merchant = null"); Return ajaxresult. error(" remove experiencer, merchant is null",null); } AuthorizationInfo info = AuthorizedUtils.getAuthorizationInfo(merchant.getAppid()); JSONObject obj = MemberUtils.unbindTester(info, tester.getWechatId()); if("0".equals(obj.getString("errcode")) && "ok".equalsIgnoreCase(obj.getString("errmsg"))){ appletsTesterService.removeById(id); } else { return AjaxResult.error(obj.getInteger("errcode"),obj.getString("errmsg")); } } return AjaxResult.success(); }Copy the code

12. Get the QR code of the experience version

public AjaxResult getQrcode(String merchantId) { Merchant merchant = merchantService.getById(merchantId); If (merchant == null) {logger.warn(" merchant is null"); Return ajaxresult. error(" get experience qr code, merchant is null",null); } AuthorizationInfo info = AuthorizedUtils.getAuthorizationInfo(merchant.getAppid()); String qrcodeUrl = CodeUtils.getQrcode(info, "pages/index/index"); Return ajaxresult. success(" operation succeeded ",qrcodeUrl); }Copy the code

13. Submit for review

public AjaxResult submitAudit(SubmitAudit submit) { Merchant merchant = merchantService.getById(submit.getMerchantId());  If (merchant == null) {logger.warn(" merchant is null"); Return ajaxresult. error(" get experience qr code, merchant is null", null); } AuthorizationInfo info = AuthorizedUtils.getAuthorizationInfo(merchant.getAppid()); List<String> categorys = submit.getCategory(); submit.setFirst_id(categorys.get(0).split("-")[0]) .setFirst_class(categorys.get(0).split("-")[1]) .setSecond_id(categorys.get(1).split("-")[0]) .setSecond_class(categorys.get(1).split("-")[1]) .setTag(submit.getTag().replace(",", " ")); List<SubmitAudit> submits = new ArrayList<>(); submits.add(submit); JSONObject sa = CodeUtils.submitAudit(info, submits); if (sa.getInteger(ResStatus.ERRCODE).equals(ResStatus.CODE) && ResStatus.MSG.equalsIgnoreCase(sa.getString(ResStatus.ERRMSG))) { JSONObject obj = CodeUtils.getAuditStatus(info, sa.getString("auditid")); if (obj.getInteger(ResStatus.ERRCODE).equals(ResStatus.CODE) && ResStatus.MSG.equalsIgnoreCase(obj.getString(ResStatus.ERRMSG))) { AppletsRelease ar = appletsReleaseService.getOne(new LambdaQueryWrapper<AppletsRelease>() .eq(AppletsRelease::getMerchantId,merchant.getId())); If (ar == null) {return ajaxresult. error(" please upload code first "); } ar.setMerchantId(submit.getMerchantId()) .setAuditId(sa.getString("auditid")) .setStatus(obj.getString("status")) .setRemark(obj.getString("screenshot")); if (AppletsRelease.STATUS_0.equals(ar.getStatus())) { ar.setRemark(AppletsRelease.MSG_0); } else if (AppletsRelease.STATUS_1.equals(ar.getStatus())) { ar.setReason(obj.getString("reason")) .setScreenshot(obj.getString("screenshot")) .setRemark(AppletsRelease.MSG_1); } else if (AppletsRelease.STATUS_2.equals(ar.getStatus())) { ar.setRemark(AppletsRelease.MSG_2); } else if (AppletsRelease.STATUS_3.equals(ar.getStatus())) { ar.setRemark(AppletsRelease.MSG_3); } else if (AppletsRelease.STATUS_4.equals(ar.getStatus())) { ar.setRemark(AppletsRelease.MSG_4); } appletsReleaseService.updateById(ar); return AjaxResult.success(); } else { return AjaxResult.error(obj.getInteger(ResStatus.ERRCODE), obj.getString(ResStatus.ERRMSG)); } } else { return AjaxResult.error(sa.getInteger(ResStatus.ERRCODE), sa.getString(ResStatus.ERRMSG)); }}Copy the code

14. Review withdrawal

Note: The number of review and withdrawal times for a single account shall not exceed 1 time per day and 10 times per month.

public AjaxResult undoCodeAudit(String[] ids) { StringBuilder sb = new StringBuilder(); for (String id : ids) { Merchant merchant = merchantService.getById(id); AuthorizationInfo info = AuthorizedUtils.getAuthorizationInfo(merchant.getAppid()); JSONObject obj = CodeUtils.undoCodeAudit(info); if (obj.getInteger(ResStatus.ERRCODE).equals(ResStatus.CODE) && ResStatus.MSG.equalsIgnoreCase(obj.getString(ResStatus.ERRMSG))) { AppletsRelease ar = appletsReleaseService.getOne(new LambdaQueryWrapper<AppletsRelease>() .eq(AppletsRelease::getMerchantId,merchant.getId())); ar.setStatus(AppletsRelease.MSG_3); appletsReleaseService.updateById(ar); } else{ sb.append(merchant.getName()+","); } } if (sb.length() == 0) { return AjaxResult.success(); } else { String name = sb.substring(0, sb.length()-1); Return ajaxresult. error(name+" audit recall failed "); }}Copy the code

15. Publish approved mini-programs

public AjaxResult releaseApplets(String[] ids) { StringBuilder sb = new StringBuilder(); for (String id : ids) { Merchant merchant = merchantService.getById(id); AuthorizationInfo info = AuthorizedUtils.getAuthorizationInfo(merchant.getAppid()); JSONObject obj = CodeUtils.release(info); if (obj.getInteger(ResStatus.ERRCODE).equals(ResStatus.CODE) && ResStatus.MSG.equalsIgnoreCase(obj.getString(ResStatus.ERRMSG))) { AppletsRelease ar = appletsReleaseService.getOne(new LambdaQueryWrapper<AppletsRelease>() .eq(AppletsRelease::getMerchantId,merchant.getId())); ar.setStatus(AppletsRelease.STATUS_5); appletsReleaseService.updateById(ar); } else{ sb.append(merchant.getName()+","); } } if (sb.length() == 0) { return AjaxResult.success(); } else { String name = sb.substring(0, sb.length()-1); Return ajaxresult. error(name+" publish failed "); }}Copy the code

16. Small program version rollback

Note:

If you do not have a previous online version, you cannot roll back

Only one version can be rolled back, that is, the current version can be rolled back. The version rollback interface cannot be invoked.

public AjaxResult revertCodeRelease(String[] ids) { StringBuilder sb = new StringBuilder(); for (String id : ids) { Merchant merchant = merchantService.getById(id); AuthorizationInfo info = AuthorizedUtils.getAuthorizationInfo(merchant.getAppid()); JSONObject obj = CodeUtils.revertCodeRelease(info); if (! (obj.getInteger(ResStatus.ERRCODE).equals(ResStatus.CODE) && ResStatus.MSG.equalsIgnoreCase(obj.getString(ResStatus.ERRMSG)))) { sb.append(merchant.getName()+","); } } if (sb.length() == 0) { return AjaxResult.success(); } else { String name = sb.substring(0, sb.length()-1); Return ajaxresult. error(null,name+" audit recall failed "); }}Copy the code

17, get small program code

public AjaxResult getMiniQrcode(@PathVariable("merchantId") String merchantId) { Merchant merchant = merchantService.getById(merchantId); If (merchant == null) {logger.warn(" merchant = null"); Return ajaxresult. error(" merchant is null",null); } String qrcode; if (StringUtils.isNotEmpty(merchant.getAppletImage())) { qrcode = merchant.getAppletImage(); } else { AuthorizationInfo info = AuthorizedUtils.getAuthorizationInfo(merchant.getAppid()); qrcode = WxUtils.getMiniQrcode(merchantId, "pages/index/index", "merchant", "miniQrcode", info.getAuthorizer_access_token()); merchant.setAppletImage(qrcode); merchantService.updateById(merchant); } return ajaxresult. success(" operation succeeded ",qrcode); }Copy the code