#假如說,有多個業務,功能模式相同的公眾號/小程序,如果只是小程序開發,那是不是需要複製多套代碼,改appid信息,在微信公眾號後台,配置域名伺服器以及密鑰等繁瑣的信息,每改一個提交發布一次,進行重複的步驟。隨著要維護的公眾號/小程式數量逐步增加,需要投入的資源以及成本也隨之增加。
有沒有想過,只需要開發一套公眾號/小程式碼,以之為模板,再來一套後台管理系統,把在微信公眾號後台做的那些事都搬到我們自己的系統中。來一個業務相同的小程序,只需要管理員授權後,只要在我們的系統中點點幾個按鈕,就可以把小程序發佈上線,一次開發供N 個公眾號使用,提供標準化的接口服務來滿足業務的基礎需求。透過掃描二維碼授權給平台,幫助N 多個公眾號代實現業務,不再需要理解繁瑣參數設置,並且密碼不提供給開發者,保證安全,真正做到解放運營同學和開發的雙手,有更多的時間去談女朋友,那該有多好。沒錯,微信第三方平台開發就是來幫你省下更多時間去把妹的神器。
相關學習推薦:微信公眾號開發教程
#概述
微信公眾平台-第三方平台(簡稱第三方平台)開放給所有通過開發者資格認證後的開發者使用。在得到公眾號或小程式運營商(簡稱經營者)授權後,第三方平台開發者可以透過呼叫微信開放平台的介面能力,為公眾號或小程式的經營者提供帳號申請、小程式創建、技術開發、產業方案、活動行銷、外掛能力等全方位服務。同一個帳號的業者可以選擇多家適合自己的第三方為其提供產品能力或委託營運。
從業務特徵上來說,第三方平台必須如圖所示:
#從具體的業務場景上來說,第三方平台包括以下情境:
提供產業解決方案,如針對電商產業的解決方案,或針對旅遊業的解決方案等;
產業:(橫向)提供更專業的營運能力,精細化營運用戶公眾號或小程式;
功能:(縱向)對公眾平台功能的最佳化,如專門優化圖文訊息視覺樣式和排版的工具,或專門客製化的CRM使用者管理功能,或功能強大的小程式插件等。
接取第三方開發的前提是要有微信開放平台應用,詳細建立步驟請參考
developers.weixin.qq.com/doc/oplatfo…
#1、取得驗證票據
#驗證票據(component_verify_ticket),在第三方平台建立審核通過後,微信伺服器會向其」授權事件接收網址」 每隔10 分鐘以POST 的方式推送component_verify_ticket
接收POST 請求後,只需直接傳回字串success。為了加強安全性,postdata 中的 xml 將使用服務申請時的加解密 key 來進行加密,在收到推播後需進行解密。
public void saveTicket(HttpServletRequest request, HttpServletResponse response) throws IOException { String msgSignature = request.getParameter("msg_signature");// 微信加密签名 String timeStamp = request.getParameter("timestamp");// 时间戳 String nonce = request.getParameter("nonce"); // 随机数 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("系统异常", e); } finally { // 响应消息 PrintWriter out = response.getWriter(); out.print("success"); } }复制代码
2、取得令牌
令牌(component_access_token)是第三方平台介面的呼叫憑證。令牌的取得是有限制的,每個令牌的有效期為 2 小時,請自行做好令牌的管理,在令牌快過期時(例如1小時50分),重新呼叫介面取得。
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("请求数据"+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("系统异常", e); } } } else { long sysTime = System.currentTimeMillis(); if (sysTime >= componentToken.getExpiresIn()) { redisService.delete(ComponentToken.COMPONENTTOKEN_ID, ComponentToken.class); componentToken = getComponentToken(ticket); }else{ } } return componentToken; }复制代码
3、快速建立小程式
快速创建小程序接口优化了小程序注册认证的流程,能帮助第三方平台迅速拓展线下商户,拓展商户的服务范围,占领小程序线下商业先机。采用法人人脸识别方式替代小额打款等认证流程,极大的减轻了小程序主体、类目资质信息收集的人力成本。第三方平台只需收集法人姓名、法人微信、企业名称、企业代码信息这四个信息,便可以向企业法人下发一条模板消息来采集法人人脸信息,完成全部注册、认证流程。以及法人收到创建成功后的小程序APPID时,同时下发模板消息给法人,提示法人进行邮箱和密码的设置,便于后续法人登陆小程序控制台进行管理。
通过该接口创建小程序默认为“已认证”。为降低接入小程序的成本门槛,通过该接口创建的小程序无需交 300 元认证费。
public AjaxResult fastRegister(String merchantId) { Merchant merchant = merchantService.getById(merchantId); if (merchant == null) { logger.warn("快速创建小程序---->失败,merchant为null"); return AjaxResult.error("快速创建小程序失败,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("快速创建小程序---->失败,component_verify_ticket为null"); return AjaxResult.error("快速创建小程序失败,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")); } } } } 复制代码
4、获取预授权码
预授权码(pre_auth_code)是第三方平台方实现授权托管的必备信息,每个预授权码有效期为 10 分钟。需要先获取令牌才能调用。
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"); }复制代码
5、引导商户授权获取授权信息
第三方服务商构建授权链接放置自己的网站,用户点击后,弹出授权页面。
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("引入用户进入授权页失败,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:引入用户进入授权页---->成功,url为:" + requestUrl); return AjaxResult.success("操作成功",requestUrl); } }复制代码
6、设置小程序基本信息
设置小程序名称,当名称没有命中关键词,则直接设置成功;当名称命中关键词,需提交证明材料,并需要审核。修改小程序的头像。修改功能介绍。修改小程序隐私设置,即修改是否可被搜索。
public AjaxResult setBasicInfo(BasicInfo basicInfo) throws IOException { Merchant merchant = merchantService.getById(basicInfo.getMerchantId()); if (merchant == null) { logger.warn("设置基本信息---->失败,merchant为null"); return AjaxResult.error("设置基本信息失败,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()); } } //修改隐私设置,即修改是否可被搜索 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(); } }复制代码
7、支付授权
即填写商户号和商户号密钥,以及上传p12证书
8、设置服务器域名
授权给第三方的小程序,其服务器域名只可以为第三方平台的服务器,当小程序通过第三方平台发布代码上线后,小程序原先自己配置的服务器域名将被删除,只保留第三方平台的域名,所以第三方平台在代替小程序发布代码之前,需要调用接口为小程序添加第三方平台自身的域名。
注意:
需要先将域名登记到第三方平台的小程序服务器域名中,才可以调用接口进行配置。
最多可以添加1000个合法服务器域名;其中,Request域名、Socket域名、Uploadfile域名、Download域名、Udp域名的设置数量均最大支持200个。
每月可提交修改申请50次。
public AjaxResult modifyDomain(ModifyDomain modifyDomain) { Merchant merchant = merchantService.getById(modifyDomain.getMerchantId()); if (merchant == null) { logger.warn("设置服务器域名---->失败,merchant为null"); return AjaxResult.error("设置服务器域名失败,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")); } } }复制代码
9、设置业务域名
授权给第三方的小程序,其业务域名只可以为第三方平台的服务器,当小程序通过第三方发布代码上线后,小程序原先自己配置的业务域名将被删除,只保留第三方平台的域名,所以第三方平台在代替小程序发布代码之前,需要调用接口为小程序添加业务域名。
注意:
需要先将业务域名登记到第三方平台的小程序业务域名中,才可以调用接口进行配置。
为授权的小程序配置域名时支持配置子域名,例如第三方登记的业务域名如为 qq.com,则可以直接将 qq.com 及其子域名(如 xxx.qq.com)也配置到授权的小程序中。
最多可以添加100个业
public AjaxResult webviewDomain(WebviewDomain webviewDomain) { Merchant merchant = merchantService.getById(webviewDomain.getMerchantId()); if (merchant == null) { logger.warn("设置业务域名---->失败,merchant为null"); return AjaxResult.error("设置业务域名失败,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")); } } }复制代码
10、上传小程序代码
第三方平台需要先将草稿添加到代码模板库,或者从代码模板库中选取某个代码模板,得到对应的模板 id(template_id);然后调用本接口可以为已授权的小程序上传代码。
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)); //接受微信返回的数据 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")); } }复制代码
11、成员管理
第三方平台在帮助旗下授权的小程序提交代码审核之前,可先让小程序运营者体验,体验之前需要将运营者的个人微信号添加到该小程序的体验者名单中。
注意: 如果运营者同时也是该小程序的管理员,则无需绑定,管理员默认有体验权限。
/** * 绑定体验者 * @parambindTester * @return */ @Override public AjaxResult bindTester(BindTester bindTester) { Merchant merchant = merchantService.getById(bindTester.getMerchantId()); if (merchant == null) { logger.warn("绑定体验者---->失败,merchant为null"); return AjaxResult.error("绑定体验者失败,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")); } } } /** * 解除体验者 * @paramtesterIds * @return */ @Override public AjaxResult unbindTester(Long[] testerIds) { for (Long id : testerIds) { AppletsTester tester = appletsTesterService.getById(id); if (tester == null) { logger.warn("解除体验者---->失败,tester为null"); return AjaxResult.error("解除体验者,tester为null",null); } Merchant merchant = merchantService.getById(tester.getMerchantId()); if (merchant == null) { logger.warn("解除体验者---->失败,merchant为null"); return AjaxResult.error("解除体验者,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(); }复制代码
12、获取体验版二维码
public AjaxResult getQrcode(String merchantId) { Merchant merchant = merchantService.getById(merchantId); if (merchant == null) { logger.warn("获取体验二维码---->失败,merchant为null"); return AjaxResult.error("获取体验二维码,merchant为null",null); } AuthorizationInfo info = AuthorizedUtils.getAuthorizationInfo(merchant.getAppid()); String qrcodeUrl = CodeUtils.getQrcode(info, "pages/index/index"); return AjaxResult.success("操作成功",qrcodeUrl); }复制代码
13、提交审核
public AjaxResult submitAudit(SubmitAudit submit) { Merchant merchant = merchantService.getById(submit.getMerchantId()); if (merchant == null) { logger.warn("获取体验二维码---->失败,merchant为null"); return AjaxResult.error("获取体验二维码,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)); } }复制代码
14、审核撤回
注意: 单个帐号每天审核撤回次数最多不超过 1 次,一个月不超过 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+"审核撤回失败"); } }复制代码
15、发布已通过审核的小程序
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+"发布失败"); } }复制代码
16、小程序版本回退
如果没有上一个线上版本,将无法回退
只能向上回退一个版本,即当前版本回退后,不能再调用版本回退接口。
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+"审核撤回失败"); } }复制代码
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); }复制代码
相关学习推荐:微信小程序教程
以上是關於微信開放平台那些事,第三方平台開發的詳細內容。更多資訊請關注PHP中文網其他相關文章!