关于前端:微信开放平台之第三方平台开发一整套流程

39次阅读

共计 20726 个字符,预计需要花费 52 分钟才能阅读完成。

如果说,有多个业务,性能模式雷同的公众号 / 小程序,如果只是小程序开发,那是不是须要复制多套代码,改 appid 信息,在微信公众号后盾,配置域名服务器以及密钥等繁琐的信息,每改一个提交公布一次,进行反复的步骤。随着要保护的公众号 / 小程序数量逐渐减少,须要投入的资源以及老本也随之减少。

欢送体验 👉:微信代小程序实现业务

有没有想过,只须要开发一套公众号 / 小程序代码,以之为模板,再来一套后盾管理系统,把在微信公众号后盾做的那些事都搬到咱们本人的零碎中。来一个业务雷同的小程序,只须要管理员受权后,只有在咱们的零碎中点点几个按钮,就能够把小程序公布上线,一次开发供 N 个公众号应用,提供标准化的接口服务来满足业务的根底需要。通过扫描二维码受权给平台,帮忙 N 多个公众号代实现业务,不再须要了解繁琐参数设置,并且明码不提供给开发者,保障平安,真正做到解放经营同学和开发的双手,有更多的工夫去谈女朋友,那该多好。没错,微信第三方平台开发就是来帮你节俭更多工夫去把妹的神器。

概述

微信公众平台 - 第三方平台(简称第三方平台)凋谢给所有通过开发者资质认证后的开发者应用。在失去公众号或小程序运营者(简称运营者)受权后,第三方平台开发者能够通过调用微信开放平台的接口能力,为公众号或小程序的运营者提供账号申请、小程序创立、技术开发、行业计划、流动营销、插件能力等全方位服务。同一个账号的运营者能够抉择多家适宜本人的第三方为其提供产品能力或委托经营。

从业务特色上来说,第三方平台必须如图所示:

从具体的业务场景上说,第三方平台包含以下场景:

提供行业解决方案,如针对电商行业的解决方案,或针对游览行业的解决方案等;
行业:(横向)提供更加业余的经营能力,精细化经营用户公众号或小程序;
性能:(纵向)对公众平台性能的优化,如专门优化图文音讯视觉款式和排版的工具,或专门定制的 CRM 用户治理性能,或功能强大的小程序插件等。

接入第三方开发的前提是要有微信开放平台利用,具体创立步骤请参考
https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/how_to_apply.html

1、获取验证票据

验证票据(component_verify_ticket),在第三方平台创立审核通过后,微信服务器会向其”受权事件接管 URL”每隔 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 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 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 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 map = new HashMap();
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 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 证书

受权给第三方的小程序,其服务器域名只能够为第三方平台的服务器,当小程序通过第三方平台公布代码上线后,小程序原先本人配置的服务器域名将被删除,只保留第三方平台的域名,所以第三方平台在代替小程序公布代码之前,须要调用接口为小程序增加第三方平台本身的域名。

留神:

1、须要先将域名注销到第三方平台的小程序服务器域名中,才能够调用接口进行配置。
2、最多能够增加 1000 个非法服务器域名;其中,Request 域名、Socket 域名、Uploadfile 域名、Download 域名、Udp 域名的设置数量均最大反对 200 个。
3、每月可提交批改申请 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 requestList = Arrays.asList(requests);
      out.setRequestdomain(requestList);
      String[] wsrequests = modifyDomain.getWsrequestdomain().split(",");
      List wsrequestList = Arrays.asList(wsrequests);
      out.setWsrequestdomain(wsrequestList);
      String[] uploads = modifyDomain.getUploaddomain().split(",");
      List uploadList = Arrays.asList(uploads);
      out.setUploaddomain(uploadList);
      String[] downloads = modifyDomain.getDownloaddomain().split(",");
      List 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、设置业务域名

受权给第三方的小程序,其业务域名只能够为第三方平台的服务器,当小程序通过第三方公布代码上线后,小程序原先本人配置的业务域名将被删除,只保留第三方平台的域名,所以第三方平台在代替小程序公布代码之前,须要调用接口为小程序增加业务域名。

留神:

1、须要先将业务域名注销到第三方平台的小程序业务域名中,才能够调用接口进行配置。
2、为受权的小程序配置域名时反对配置子域名,例如第三方注销的业务域名如为 qq.com,则能够间接将 qq.com 及其子域名(如 xxx.qq.com)也配置到受权的小程序中。
3、最多能够增加 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 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 map = new HashMap<>();
  map.put("merchantId", model.getMerchantId());
  map.put("userVersion", commitIn.getUser_version());
  obj.put("ext", map);
  map = new HashMap<>();
  Map 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()
              .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 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 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()
                  .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()
                  .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()
                  .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、小程序版本回退

留神:

1、如果没有上一个线上版本,将无奈回退
2、只能向上回退一个版本,即以后版本回退后,不能再调用版本回退接口

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);
}

上一篇:缓存穿透,击穿,雪崩以及解决方案,干货满满

正文完
 0