準備工作
第三方收集法人微信、法人姓名、企業名稱、信用代碼四個商戶信息外加第三方客服電話,用以調用接口創建小程序;參考文檔
發送請求
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;
}
}