


Things about WeChat open platform and third-party platform development
Sep 15, 2020 pm 04:34 PM

Related learning recommendations:
Overview
WeChat public platform- The third-party platform (referred to as the third-party platform) is open to all developers who have passed the developer qualification certification. After being authorized by the operator of the official account or mini program (referred to as the operator), the third-party platform developer can provide the operator of the official account or mini program with account application, mini program creation, and technology by calling the interface capabilities of the WeChat open platform. Comprehensive services such as development, industry solutions, event marketing, and plug-in capabilities. Operators of the same account can choose multiple third parties that are suitable for them to provide product capabilities or entrust operations. In terms of business characteristics, the third-party platform must be as shown in the figure:

#1. Obtain the verification ticket
Verification ticket (component_verify_ticket). After the third-party platform is created and approved, the WeChat server will Push component_verify_ticket to its "authorized event receiving URL" by POST every 10 minutes. After receiving the POST request, just return the string success directly. In order to enhance security, the xml in postdata will be encrypted using the encryption and decryption key when applying for the service, and needs to be decrypted after receiving the push.public?void?saveTicket(HttpServletRequest?request,?HttpServletResponse?response)?throws?IOException?{ ??String?msgSignature?=?request.getParameter("msg_signature");//?微信加密簽名 ??String?timeStamp?=?request.getParameter("timestamp");//?時(shí)間戳???? ??String?nonce?=?request.getParameter("nonce");?//?隨機(jī)數(shù)?? ??BufferedReader?br?=?new?BufferedReader(new?InputStreamReader(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("系統(tǒng)異常",?e); ??}?finally?{ ????//?響應(yīng)消息 ????PrintWriter?out?=?response.getWriter(); ????out.print("success"); ??} }復(fù)制代碼
2. Obtain token
Token (component_access_token) is the calling credential for the third-party platform interface. The acquisition of tokens is limited. Each token is valid for 2 hours. Please manage the tokens yourself. When the token is about to expire (for example, 1 hour and 50 minutes), call the interface again to obtain it.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);?//第三方平臺appsecret ??map.put("component_verify_ticket",?ticket);? ??String?outputStr?=?JSONObject.toJSONString(map); ??logger.warn("請求數(shù)據(jù)"+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("系統(tǒng)異常",?e); ????} ??} }?else?{ ??long?sysTime?=?System.currentTimeMillis(); ??if?(sysTime?>=?componentToken.getExpiresIn())?{ ????redisService.delete(ComponentToken.COMPONENTTOKEN_ID,?ComponentToken.class); ????componentToken?=?getComponentToken(ticket); ??}else{ ??} } return?componentToken; }復(fù)制代碼

3. Quickly create small programs
快速創(chuàng)建小程序接口優(yōu)化了小程序注冊認(rèn)證的流程,能幫助第三方平臺迅速拓展線下商戶,拓展商戶的服務(wù)范圍,占領(lǐng)小程序線下商業(yè)先機(jī)。采用法人人臉識別方式替代小額打款等認(rèn)證流程,極大的減輕了小程序主體、類目資質(zhì)信息收集的人力成本。第三方平臺只需收集法人姓名、法人微信、企業(yè)名稱、企業(yè)代碼信息這四個(gè)信息,便可以向企業(yè)法人下發(fā)一條模板消息來采集法人人臉信息,完成全部注冊、認(rèn)證流程。以及法人收到創(chuàng)建成功后的小程序APPID時(shí),同時(shí)下發(fā)模板消息給法人,提示法人進(jìn)行郵箱和密碼的設(shè)置,便于后續(xù)法人登陸小程序控制臺進(jìn)行管理。
通過該接口創(chuàng)建小程序默認(rèn)為“已認(rèn)證”。為降低接入小程序的成本門檻,通過該接口創(chuàng)建的小程序無需交 300 元認(rèn)證費(fèi)。


public?AjaxResult?fastRegister(String?merchantId)?{ ??Merchant?merchant?=?merchantService.getById(merchantId); ??if?(merchant?==?null)?{ ??????logger.warn("快速創(chuàng)建小程序---->失敗,merchant為null"); ??????return?AjaxResult.error("快速創(chuàng)建小程序失敗,merchant為null",null); ??}?else?{ ??????RedisService<ComponentVerifyTicket>?redisService?=?RedisService.load(); ??????ComponentVerifyTicket?componentVerifyTicket?=?redisService.load(ComponentVerifyTicket.COMPONENT_VERIFY_TICKET_ID, ??????????????ComponentVerifyTicket.class); ????if?(componentVerifyTicket?==?null)?{ ????????logger.warn("快速創(chuàng)建小程序---->失敗,component_verify_ticket為null"); ????????return?AjaxResult.error("快速創(chuàng)建小程序失敗,component_verify_ticket為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")); ????????} ????} } }? 復(fù)制代碼
4、獲取預(yù)授權(quán)碼
預(yù)授權(quán)碼(pre_auth_code)是第三方平臺方實(shí)現(xiàn)授權(quán)托管的必備信息,每個(gè)預(yù)授權(quán)碼有效期為 10 分鐘。需要先獲取令牌才能調(diào)用。
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"); }復(fù)制代碼
5、引導(dǎo)商戶授權(quán)獲取授權(quán)信息
第三方服務(wù)商構(gòu)建授權(quán)鏈接放置自己的網(wǎng)站,用戶點(diǎn)擊后,彈出授權(quán)頁面。



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("引入用戶進(jìn)入授權(quán)頁失敗,component_verify_ticket為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("步驟2:引入用戶進(jìn)入授權(quán)頁---->成功,url為:"?+?requestUrl); ??return?AjaxResult.success("操作成功",requestUrl); ?? } }復(fù)制代碼
6、設(shè)置小程序基本信息
設(shè)置小程序名稱,當(dāng)名稱沒有命中關(guān)鍵詞,則直接設(shè)置成功;當(dāng)名稱命中關(guān)鍵詞,需提交證明材料,并需要審核。修改小程序的頭像。修改功能介紹。修改小程序隱私設(shè)置,即修改是否可被搜索。


public?AjaxResult?setBasicInfo(BasicInfo?basicInfo)?throws?IOException?{ ??Merchant?merchant?=?merchantService.getById(basicInfo.getMerchantId()); ??if?(merchant?==?null)?{ ??????logger.warn("設(shè)置基本信息---->失敗,merchant為null"); ??????return?AjaxResult.error("設(shè)置基本信息失敗,merchant為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()); ??????????} ??????} ??????//修改隱私設(shè)置,即修改是否可被搜索 ??????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(); ??} }復(fù)制代碼
7、支付授權(quán)
即填寫商戶號和商戶號密鑰,以及上傳p12證書

8、設(shè)置服務(wù)器域名
授權(quán)給第三方的小程序,其服務(wù)器域名只可以為第三方平臺的服務(wù)器,當(dāng)小程序通過第三方平臺發(fā)布代碼上線后,小程序原先自己配置的服務(wù)器域名將被刪除,只保留第三方平臺的域名,所以第三方平臺在代替小程序發(fā)布代碼之前,需要調(diào)用接口為小程序添加第三方平臺自身的域名。
注意:
需要先將域名登記到第三方平臺的小程序服務(wù)器域名中,才可以調(diào)用接口進(jìn)行配置。
最多可以添加1000個(gè)合法服務(wù)器域名;其中,Request域名、Socket域名、Uploadfile域名、Download域名、Udp域名的設(shè)置數(shù)量均最大支持200個(gè)。
每月可提交修改申請50次。


public?AjaxResult?modifyDomain(ModifyDomain?modifyDomain)?{ ??Merchant?merchant?=?merchantService.getById(modifyDomain.getMerchantId()); ??if?(merchant?==?null)?{ ??????logger.warn("設(shè)置服務(wù)器域名---->失敗,merchant為null"); ??????return?AjaxResult.error("設(shè)置服務(wù)器域名失敗,merchant為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")); ??????} ??} }復(fù)制代碼
9、設(shè)置業(yè)務(wù)域名
授權(quán)給第三方的小程序,其業(yè)務(wù)域名只可以為第三方平臺的服務(wù)器,當(dāng)小程序通過第三方發(fā)布代碼上線后,小程序原先自己配置的業(yè)務(wù)域名將被刪除,只保留第三方平臺的域名,所以第三方平臺在代替小程序發(fā)布代碼之前,需要調(diào)用接口為小程序添加業(yè)務(wù)域名。
注意:
需要先將業(yè)務(wù)域名登記到第三方平臺的小程序業(yè)務(wù)域名中,才可以調(diào)用接口進(jìn)行配置。
為授權(quán)的小程序配置域名時(shí)支持配置子域名,例如第三方登記的業(yè)務(wù)域名如為 qq.com,則可以直接將 qq.com 及其子域名(如 xxx.qq.com)也配置到授權(quán)的小程序中。
最多可以添加100個(gè)業(yè)


public?AjaxResult?webviewDomain(WebviewDomain?webviewDomain)?{ ??Merchant?merchant?=?merchantService.getById(webviewDomain.getMerchantId()); ??if?(merchant?==?null)?{ ??????logger.warn("設(shè)置業(yè)務(wù)域名---->失敗,merchant為null"); ??????return?AjaxResult.error("設(shè)置業(yè)務(wù)域名失敗,merchant為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")); ??????} ??} }復(fù)制代碼
10、上傳小程序代碼
第三方平臺需要先將草稿添加到代碼模板庫,或者從代碼模板庫中選取某個(gè)代碼模板,得到對應(yīng)的模板 id(template_id);然后調(diào)用本接口可以為已授權(quán)的小程序上傳代碼。

public?AjaxResult?commit(CommitModel?model)?{ ??Merchant?merchant?=?merchantService.selectMerchantById(model.getMerchantId()); ??if?(merchant?==?null)?{ ??????logger.warn("上傳代碼---->失敗,merchant為null"); ??????return?AjaxResult.error("上傳代碼,merchant為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)); ??//接受微信返回的數(shù)據(jù) ??obj?=?CodeUtils.commit(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")); ??} }復(fù)制代碼

11、成員管理
第三方平臺在幫助旗下授權(quán)的小程序提交代碼審核之前,可先讓小程序運(yùn)營者體驗(yàn),體驗(yàn)之前需要將運(yùn)營者的個(gè)人微信號添加到該小程序的體驗(yàn)者名單中。
注意: 如果運(yùn)營者同時(shí)也是該小程序的管理員,則無需綁定,管理員默認(rèn)有體驗(yàn)權(quán)限。

/** *?綁定體驗(yàn)者 *?@parambindTester *?@return */ @Override public?AjaxResult?bindTester(BindTester?bindTester)?{ ??Merchant?merchant?=?merchantService.getById(bindTester.getMerchantId()); ??if?(merchant?==?null)?{ ??????logger.warn("綁定體驗(yàn)者---->失敗,merchant為null"); ??????return?AjaxResult.error("綁定體驗(yàn)者失敗,merchant為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")); ????} } } /** *?解除體驗(yàn)者 *?@paramtesterIds *?@return */ @Override public?AjaxResult?unbindTester(Long[]?testerIds)?{ ??for?(Long?id?:?testerIds)?{ ??????AppletsTester?tester?=?appletsTesterService.getById(id); ??????if?(tester?==?null)?{ ??????????logger.warn("解除體驗(yàn)者---->失敗,tester為null"); ??????????return?AjaxResult.error("解除體驗(yàn)者,tester為null",null); ??????} ??????Merchant?merchant?=?merchantService.getById(tester.getMerchantId()); ??????if?(merchant?==?null)?{ ??????????logger.warn("解除體驗(yàn)者---->失敗,merchant為null"); ??????????return?AjaxResult.error("解除體驗(yàn)者,merchant為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(); }復(fù)制代碼
12、獲取體驗(yàn)版二維碼

public?AjaxResult?getQrcode(String?merchantId)?{ ??Merchant?merchant?=?merchantService.getById(merchantId); ??if?(merchant?==?null)?{ ??????logger.warn("獲取體驗(yàn)二維碼---->失敗,merchant為null"); ??????return?AjaxResult.error("獲取體驗(yàn)二維碼,merchant為null",null); ??} ??AuthorizationInfo?info?=?AuthorizedUtils.getAuthorizationInfo(merchant.getAppid()); ??String?qrcodeUrl?=??CodeUtils.getQrcode(info,?"pages/index/index"); ??return?AjaxResult.success("操作成功",qrcodeUrl); }復(fù)制代碼
13、提交審核

public?AjaxResult?submitAudit(SubmitAudit?submit)?{ ??Merchant?merchant?=?merchantService.getById(submit.getMerchantId()); ??if?(merchant?==?null)?{ ??????logger.warn("獲取體驗(yàn)二維碼---->失敗,merchant為null"); ??????return?AjaxResult.error("獲取體驗(yàn)二維碼,merchant為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("請先上傳代碼"); ??????????} ??????????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)); ??} }復(fù)制代碼
14、審核撤回
注意: 單個(gè)帳號每天審核撤回次數(shù)最多不超過 1 次,一個(gè)月不超過 10 次。

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+"審核撤回失敗"); ??} }復(fù)制代碼
15、發(fā)布已通過審核的小程序

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+"發(fā)布失敗"); ??} }復(fù)制代碼
16、小程序版本回退
如果沒有上一個(gè)線上版本,將無法回退
只能向上回退一個(gè)版本,即當(dāng)前版本回退后,不能再調(diào)用版本回退接口。

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+"審核撤回失敗"); ??} }復(fù)制代碼
17、獲取小程序碼

public?AjaxResult?getMiniQrcode(@PathVariable("merchantId")?String?merchantId)?{ ??Merchant?merchant?=?merchantService.getById(merchantId); ??if?(merchant?==?null)?{ ??????logger.warn("獲取小程序碼---->失敗,merchant為null"); ??????return?AjaxResult.error("獲取小程序碼,merchant為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("操作成功",qrcode); }復(fù)制代碼
相關(guān)學(xué)習(xí)推薦:微信小程序教程
The above is the detailed content of Things about WeChat open platform and third-party platform development. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
