微信第三方平台创建小程序

准备工作

第三方收集法人微信、法人姓名、企业名称、信用代码四个商户信息外加第三方客服电话,用以调用接口创建小程序;参考文档

发送请求

package com.litte.util;

import com.litte.entity.reception.TCreateApplets;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @program: litte
 * @description: 第三方创建小程序工具类
 * @author: Mr.Jkx
 * @create: 2019-10-14 11:11
 */
public class CreateApplets {
    private static final Logger LOGGER = LoggerFactory.getLogger(CreateApplets.class);
    // 创建小程序接口
    private static final String CREATE_APPLETS_URL = "https://api.weixin.qq.com/cgi-bin/component/fastregisterweapp?action=create&component_access_token=TOKEN";
    // 查询创建任务状态
    private static final String CREATE_APPLETS_STATUS_URL = "https://api.weixin.qq.com/cgi-bin/component/fastregisterweapp?action=search&component_access_token=TOKEN";

    /**
     * @Description: 第三方创建小程序
     * @Author: Mr.Jkx
     * @date: 2019/10/14 11:37
     */
    public static Map<String, Object> create(TCreateApplets tCreateApplets) throws IOException {
        Map<String, Object> map = new HashMap<>();
        JSONObject jsonData = new JSONObject();
        jsonData.accumulate("name", tCreateApplets.getCompanyName());
        jsonData.accumulate("code", tCreateApplets.getCreditCode());
        jsonData.accumulate("code_type", tCreateApplets.getCompanyCodeType());
        jsonData.accumulate("legal_persona_wechat", tCreateApplets.getFrWx());
        jsonData.accumulate("legal_persona_name", tCreateApplets.getFrName());
        jsonData.accumulate("component_phone", tCreateApplets.getKfTel());
        String url = CREATE_APPLETS_URL.replace("TOKEN", tCreateApplets.getComponentAccessToken());
        JSONObject retStr = WinxinUtil.doPostStr(url, jsonData.toString());
        LOGGER.info("==========第三方创建小程序=====回执信息{}", retStr);
        if (StringUtils.equals("0", retStr.getString("errcode"))) {
            map.put("statusCode", "200");
        }
        return map;
    }

    /**
     * @Description: 查询创建任务状态
     * @Author: Mr.Jkx
     * @date: 2019/10/14 11:53
     */
    public static Map<String, Object> createStatus(TCreateApplets tCreateApplets) throws IOException {
        Map<String, Object> map = new HashMap<>();
        JSONObject jsonData = new JSONObject();
        jsonData.accumulate("name", tCreateApplets.getCompanyName());
        jsonData.accumulate("legal_persona_wechat", tCreateApplets.getFrWx());
        jsonData.accumulate("legal_persona_name", tCreateApplets.getFrName());
        String url = CREATE_APPLETS_STATUS_URL.replace("TOKEN", tCreateApplets.getComponentAccessToken());
        JSONObject retStr = WinxinUtil.doPostStr(url, jsonData.toString());
        LOGGER.info("==========第三方创建小程序,查询创建任务状态=====回执信息{}", retStr);
        if (StringUtils.equals("0", retStr.getString("errcode"))) {
            map.put("msg", "创建成功!");
        } else if (StringUtils.equals("89249", retStr.getString("errcode"))) {
            map.put("msg", "该主体已有任务执行中,距创建任务 24h 后再试!");
        } else if (StringUtils.equals("86004", retStr.getString("errcode"))) {
            map.put("msg", "微信号无效!");
        } else if (StringUtils.equals("61070", retStr.getString("errcode"))) {
            map.put("msg", "法人姓名与微信号不一致!");
        } else if (StringUtils.equals("89248", retStr.getString("errcode"))) {
            map.put("msg", "企业代码类型无效,请选择正确类型填写!");
        } else if (StringUtils.equals("89250", retStr.getString("errcode"))) {
            map.put("msg", "未找到该任务!");
        } else if (StringUtils.equals("89251", retStr.getString("errcode"))) {
            map.put("msg", "待法人人脸核身校验!");
        } else if (StringUtils.equals("89252", retStr.getString("errcode"))) {
            map.put("msg", "法人或者企业信息一致性校验中!");
        } else {
            map.put("msg", "查询失败,请联系管理员!");
        }
        return map;
    }
}
发布了35 篇原创文章 · 获赞 27 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_43948057/article/details/102579264