Browse Source

update tt

master
xhxu 2 years ago
parent
commit
bd8dfa4772
11 changed files with 226 additions and 142 deletions
  1. +1
    -0
      mallinkService/src/main/java/com/iformall/enums/EnumAppType.java
  2. +2
    -1
      mallinkService/src/main/java/com/iformall/service/TtMerchantPoiService.java
  3. +47
    -0
      mallinkService/src/main/java/com/iformall/service/impl/TtMerchantPoiServiceImpl.java
  4. +8
    -0
      mallinkService/src/main/java/com/iformall/service/toutiao/api/TtOpenMaService.java
  5. +1
    -0
      mallinkService/src/main/java/com/iformall/service/toutiao/api/bean/TtOpenGsonBuilder.java
  6. +47
    -0
      mallinkService/src/main/java/com/iformall/service/toutiao/api/bean/TtOpenShopMaterial.java
  7. +47
    -0
      mallinkService/src/main/java/com/iformall/service/toutiao/api/bean/TtOpenShopMaterialGsonAdapter.java
  8. +8
    -0
      mallinkService/src/main/java/com/iformall/service/toutiao/api/impl/TtOpenMaServiceImpl.java
  9. +64
    -42
      mlToutiaoOpen/src/main/java/com/iformall/controller/TtMerchantPoiController.java
  10. +0
    -98
      mlToutiaoOpen/src/main/java/com/iformall/controller/UploadController.java
  11. +1
    -1
      mlToutiaoOpen/src/main/java/com/iformall/utils/UrlCheck.java

+ 1
- 0
mallinkService/src/main/java/com/iformall/enums/EnumAppType.java View File

@@ -11,6 +11,7 @@ public enum EnumAppType {
C(2, "C端"),
MP_S(3,"公众号-服务号"),
MP_P(4, "公众号-订阅号"),
A(5, "A端"),
;

public static EnumAppType getEnum(Integer code) {


+ 2
- 1
mallinkService/src/main/java/com/iformall/service/TtMerchantPoiService.java View File

@@ -2,6 +2,7 @@ package com.iformall.service;

import com.github.pagehelper.PageInfo;
import com.iformall.domain.po.TtMerchantPoi;
import com.iformall.domain.po.WxAppinfo;

/**
* @author gongbiao
@@ -20,5 +21,5 @@ public interface TtMerchantPoiService {

TtMerchantPoi getById(Long id);

boolean addShopMaterial(WxAppinfo appinfo, TtMerchantPoi merchantPoi);
}

+ 47
- 0
mallinkService/src/main/java/com/iformall/service/impl/TtMerchantPoiServiceImpl.java View File

@@ -1,15 +1,26 @@
package com.iformall.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.iformall.domain.po.TtMerchantPoi;
import com.iformall.domain.po.WxAppinfo;
import com.iformall.enums.EnumAppPlat;
import com.iformall.enums.EnumAppType;
import com.iformall.mapper.TtMerchantPoiMapper;
import com.iformall.mapper.WxAppinfoMapper;
import com.iformall.service.TtMerchantPoiService;
import com.iformall.service.toutiao.FmTtOpenService;
import com.iformall.service.toutiao.api.TtOpenMaService;
import com.iformall.service.toutiao.api.bean.TtOpenResult;
import com.iformall.service.toutiao.api.bean.TtOpenShopMaterial;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;


/**
* @author gongbiao
@@ -22,6 +33,12 @@ public class TtMerchantPoiServiceImpl implements TtMerchantPoiService {
@Autowired
TtMerchantPoiMapper ttMerchantPoiMapper;

@Autowired
WxAppinfoMapper wxAppinfoMapper;

@Autowired
protected FmTtOpenService openService;


@Override
public PageInfo<TtMerchantPoi> listAsPage(TtMerchantPoi record, Integer pageIndex, Integer pageSize) {
@@ -33,5 +50,35 @@ public class TtMerchantPoiServiceImpl implements TtMerchantPoiService {
return ttMerchantPoiMapper.selectById(id);
}

@Override
public boolean addShopMaterial(WxAppinfo appinfo, TtMerchantPoi merchantPoi) {

WxAppinfo appinfoQ = new WxAppinfo();
appinfoQ.setTenantId(appinfo.getTenantId());
appinfoQ.setPlat(EnumAppPlat.TOUTIAO.getCode());
appinfoQ.setType(EnumAppType.A.getCode());
WxAppinfo ttopen = wxAppinfoMapper.selectOne(new QueryWrapper<>(appinfoQ));

TtOpenShopMaterial shopMaterial = new TtOpenShopMaterial();
shopMaterial.setClientKey(ttopen.getAppId());
shopMaterial.setSupplierExtId(merchantPoi.getSupplierExtId());
shopMaterial.setBizLicencePath(merchantPoi.getBizLicencePath());
shopMaterial.setContractPath(merchantPoi.getContractPath());
shopMaterial.setQualMaterial(merchantPoi.getQualMaterial());
shopMaterial.setExpireTime(merchantPoi.getExpireTime());
shopMaterial.setAdditionalQual(merchantPoi.getAdditionalQual());

TtOpenMaService openMaService = openService.getTtOpenComponentService().getTtMaServiceByAppid(appinfo.getAppId());

TtOpenResult res = openMaService.addShopMaterial(shopMaterial);
if(res.isSuccess()){
merchantPoi.setUpdateDate(new Date());
ttMerchantPoiMapper.updateById(merchantPoi);
return true;
}
logger.error("提交商铺资质材料error"+ res.getMessage());
return false;
}


}

+ 8
- 0
mallinkService/src/main/java/com/iformall/service/toutiao/api/TtOpenMaService.java View File

@@ -1,6 +1,7 @@
package com.iformall.service.toutiao.api;

import com.iformall.service.toutiao.api.bean.TtOpenResult;
import com.iformall.service.toutiao.api.bean.TtOpenShopMaterial;
import com.iformall.service.toutiao.miniapp.TtMaService;
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.common.error.WxErrorException;
@@ -237,6 +238,11 @@ public interface TtOpenMaService extends TtMaService {
*/
String API_UPLOAD_MATERIAL = "https://open.microapp.bytedance.com/openapi/v1/microapp/upload_material";

/**
* 提交商铺资质材料
*/
String API_ADD_SHOP_MATERIAL = "https://open.microapp.bytedance.com/openapi/v1/microapp/operation/add_shop_material";


/**
* 获得小程序的域名配置信息
@@ -490,6 +496,8 @@ public interface TtOpenMaService extends TtMaService {

String mediaUpload(Integer mediaType, File file) throws WxErrorException;

TtOpenResult addShopMaterial(TtOpenShopMaterial shopMaterial)throws WxErrorException;

// /**
// * 小程序用户隐私保护指引服务
// *


+ 1
- 0
mallinkService/src/main/java/com/iformall/service/toutiao/api/bean/TtOpenGsonBuilder.java View File

@@ -14,6 +14,7 @@ public class TtOpenGsonBuilder {
INSTANCE.registerTypeAdapter(TtOpenNotifyMsg.class, new TtOpenNotifyMsgGsonAdapter());
INSTANCE.registerTypeAdapter(TtOpenAuthorizationInfo.class, new TtOpenAuthorizationInfoGsonAdapter());
INSTANCE.registerTypeAdapter(TtOpenRetrieveCode.class, new TtOpenRetrieveCodeGsonAdapter());
INSTANCE.registerTypeAdapter(TtOpenShopMaterial.class, new TtOpenShopMaterialGsonAdapter());

}



+ 47
- 0
mallinkService/src/main/java/com/iformall/service/toutiao/api/bean/TtOpenShopMaterial.java View File

@@ -0,0 +1,47 @@
package com.iformall.service.toutiao.api.bean;

import com.google.gson.JsonArray;
import lombok.*;

import java.io.Serializable;

/**
* @author S
*/
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class TtOpenShopMaterial implements Serializable {


private static final long serialVersionUID = -7209805209834111965L;

private String clientKey;//服务商在抖音开放平台的应用唯一标识

/**
* 接入方店铺 ID
*/
private String supplierExtId;

/**
* 商铺营业执照路径
*/
private String bizLicencePath;//商铺营业执照路径

private String contractPath;//商家授权函

private String qualMaterial;//商铺行业资质材料信息

//2019-01-14 12:45:10
private String expireTime;

private String additionalQual;//其他补充资质


public String toJson() {
return TtOpenGsonBuilder.create().toJson(this);
}

}

+ 47
- 0
mallinkService/src/main/java/com/iformall/service/toutiao/api/bean/TtOpenShopMaterialGsonAdapter.java View File

@@ -0,0 +1,47 @@
/*
* KINGSTAR MEDIA SOLUTIONS Co.,LTD. Copyright c 2005-2013. All rights reserved.
*
* This source code is the property of KINGSTAR MEDIA SOLUTIONS LTD. It is intended
* only for the use of KINGSTAR MEDIA application development. Reengineering, reproduction
* arose from modification of the original source, or other redistribution of this source
* is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD.
*/
package com.iformall.service.toutiao.api.bean;

import com.google.gson.*;
import org.apache.commons.lang3.StringUtils;

import java.lang.reflect.Type;


/**
* @author Daniel Qian
*/
public class TtOpenShopMaterialGsonAdapter implements JsonSerializer<TtOpenShopMaterial> {

@Override
public JsonElement serialize(TtOpenShopMaterial openShopMaterial, Type typeOfSrc, JsonSerializationContext context) {
return convertToJson(openShopMaterial);
}

protected JsonObject convertToJson(TtOpenShopMaterial openShopMaterial) {
JsonObject json = new JsonObject();
json.addProperty("client_key", openShopMaterial.getClientKey());
json.addProperty("supplier_ext_id", openShopMaterial.getSupplierExtId());
json.addProperty("biz_licence_path", openShopMaterial.getBizLicencePath());
json.addProperty("contract_path", openShopMaterial.getContractPath());

if(StringUtils.isNotBlank(openShopMaterial.getQualMaterial())){
JsonArray qmJsonArray = new JsonParser().parse(openShopMaterial.getQualMaterial()).getAsJsonArray();
json.add("qual_material",qmJsonArray);
}
json.addProperty("expire_time", openShopMaterial.getExpireTime());

if(StringUtils.isNotBlank(openShopMaterial.getAdditionalQual())){
JsonArray aqJsonArray = new JsonParser().parse(openShopMaterial.getAdditionalQual()).getAsJsonArray();
json.add("additional_qual",aqJsonArray);
}
return json;
}

}

+ 8
- 0
mallinkService/src/main/java/com/iformall/service/toutiao/api/impl/TtOpenMaServiceImpl.java View File

@@ -11,6 +11,7 @@ import com.iformall.service.toutiao.api.TtOpenMaService;
import com.iformall.service.toutiao.api.bean.TtOpenGsonBuilder;
import com.iformall.service.toutiao.api.bean.TtOpenMaQrcode;
import com.iformall.service.toutiao.api.bean.TtOpenResult;
import com.iformall.service.toutiao.api.bean.TtOpenShopMaterial;
import com.iformall.service.toutiao.miniapp.TtMaQrcode;
import com.iformall.service.toutiao.miniapp.TtQrcodeRequestExecutor;
import com.iformall.service.toutiao.miniapp.impl.TtMaServiceImpl;
@@ -682,6 +683,13 @@ public class TtOpenMaServiceImpl extends TtMaServiceImpl implements TtOpenMaServ
return this.execute(executor, uri, file);
}

@Override
public TtOpenResult addShopMaterial(TtOpenShopMaterial shopMaterial)throws WxErrorException {
String uri = API_ADD_SHOP_MATERIAL + "?component_appid=" + ttOpenComponentService.getWxOpenConfigStorage().getComponentAppId();
String response = ttOpenComponentService.postByAppAccessToken(appId,uri,shopMaterial.toJson(),"authorizer_access_token");
return TtOpenGsonBuilder.create().fromJson(response, TtOpenResult.class);
}


/**
* 将字符串对象转化为GsonArray对象


+ 64
- 42
mlToutiaoOpen/src/main/java/com/iformall/controller/TtMerchantPoiController.java View File

@@ -1,21 +1,21 @@
package com.iformall.controller;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import com.iformall.common.ErrorCode;
import com.iformall.common.Result;
import com.iformall.common.ResultData;
import com.iformall.controller.base.BaseController;
import com.iformall.domain.po.BaseEntity;
import com.iformall.domain.po.TtMerchantPoi;
import com.iformall.domain.po.WxAppinfo;
import com.iformall.enums.EnumMeterialType;
import com.iformall.service.TtMerchantPoiService;
import com.iformall.service.WxAppinfoService;
import com.iformall.service.toutiao.FmTtOpenService;
import com.iformall.service.toutiao.api.TtOpenMaService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.common.error.WxErrorException;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -23,10 +23,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

/**
@@ -40,6 +36,8 @@ public class TtMerchantPoiController extends BaseController {
@Autowired
private TtMerchantPoiService ttMerchantPoiService;

private WxAppinfoService appinfoService;

@Autowired
protected FmTtOpenService openService;

@@ -135,54 +133,78 @@ public class TtMerchantPoiController extends BaseController {
}
}


@PostMapping(value = "/upload_material1", consumes = "multipart/*", headers = "content-type=multipart/form-data")
@ApiOperation("上传图片")
public ResultData uploadMaterial(@RequestParam("file") MultipartFile multiReq) {
logger.info("[" + getIpAddr() + "] TtMerchantPoiController::upload_material");
String appId = "ttef6599d8705b49b101";
/**
* @param
* @return
* @throws Exception
*/
@PostMapping(value = "/add_shop_material")
@ApiOperation("提交商铺资质材料")
public ResultData addShopMaterial(@RequestBody Map<String, String> param) {
logger.info("[" + getIpAddr() + "] TtMerchantPoiController::add_shop_material");
String appId = param.get("appId");
if(StringUtils.isBlank(appId)){
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL);
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"appId为空");
}
String materialTypeStr = "7";
Integer materialType = null;
if(StringUtils.isNotBlank(materialTypeStr)){
try{
materialType = Integer.parseInt(materialTypeStr);
}catch (Exception e){ }
WxAppinfo appinfo = appinfoService.getByAppId(appId);
if(appinfo == null){
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"找不到小程序信息");
}
if(materialType == null){
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL);

String supplierExtId = param.get("supplierExtId");
if(StringUtils.isBlank(supplierExtId)){
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"商户ID为空");
}

EnumMeterialType enumMeterialType = EnumMeterialType.getByCode(materialType);
if(enumMeterialType == null){
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR);
TtMerchantPoi merchantPoi = ttMerchantPoiService.getById(Long.parseLong(supplierExtId));
if(merchantPoi == null){
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"查询不到商户");
}

long size = multiReq.getSize();
final long length = enumMeterialType.getSize();
if (size > length) {
return new ResultData(ErrorCode.PICTURE_SIZE_EXCEED);
String bizLicencePath = param.get("bizLicencePath");
if(StringUtils.isBlank(bizLicencePath)){
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"商铺营业执照为空");
}
merchantPoi.setBizLicencePath(bizLicencePath);

String fileFormat = "";
try {
int dot = multiReq.getOriginalFilename().lastIndexOf('.');
if (dot >= 0) {
fileFormat = multiReq.getOriginalFilename().substring(dot, multiReq.getOriginalFilename().length());
String contractPath = param.get("contract_path");
if(StringUtils.isBlank(contractPath)){
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"授权函为空");
}
merchantPoi.setContractPath(contractPath);

String expireTime = param.get("expire_time");
if(StringUtils.isBlank(expireTime)){
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"过期时间为空");
}
String regex = "(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29)(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29) ";
if(!expireTime.matches(regex)){
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"过期时间格式 YYYY-MM-DD");
}
merchantPoi.setExpireTime(expireTime);
String qualMaterial = param.get("qual_material");
if(StringUtils.isNotBlank(qualMaterial)){
try{
JSON.parse(qualMaterial);
merchantPoi.setQualMaterial(qualMaterial);
}catch(Exception e){
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"商铺行业资质材料信息格式不正确");
}
}
String additionalQual = param.get("additional_qual");
if(StringUtils.isNotBlank(additionalQual)){
try{
JSON.parse(additionalQual);
merchantPoi.setAdditionalQual(additionalQual);
}catch(Exception e){
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"其他补充资质信息格式不正确");
}
}

TtOpenMaService openMaService = openService.getTtOpenComponentService().getTtMaServiceByAppid(appId);
String res = openMaService.mediaUpload(materialType, fileFormat, multiReq.getInputStream());
return new ResultData(res);
boolean b = ttMerchantPoiService.addShopMaterial(appinfo,merchantPoi);

} catch (Exception e) {
logger.error("解析图片",e);
return new ResultData(ErrorCode.PICTURE_ANALYZING_ERROR);
}
return new ResultData(b);
}



}

+ 0
- 98
mlToutiaoOpen/src/main/java/com/iformall/controller/UploadController.java View File

@@ -1,98 +0,0 @@
package com.iformall.controller;


import com.iformall.common.ErrorCode;
import com.iformall.common.ResultData;
import com.iformall.controller.base.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "upload")
@Api(description = "文件上传接口")
public class UploadController extends BaseController {

private final Logger logger = LoggerFactory.getLogger(this.getClass());


/**
* 上传文件
*
* @param multiReq
* @return
* @throws Exception
*/
@PostMapping(value = "/awsFileUpload", consumes = "multipart/*", headers = "content-type=multipart/form-data")
@ApiOperation("上传文件")
public ResultData awsfileUpload(@RequestParam("file") MultipartFile multiReq) {
logger.info("[" + getIpAddr() + "] UploadController::awsfileUpload");



try {
int dot = multiReq.getOriginalFilename().lastIndexOf('.');
String fileFormat = "";
if (dot >= 0) {
fileFormat = multiReq.getOriginalFilename().substring(dot, multiReq.getOriginalFilename().length());
}
return new ResultData(fileFormat);

} catch (Exception e) {
logger.error(e.getMessage());
return new ResultData(ErrorCode.PICTURE_ANALYZING_ERROR);
}
}


/**
* 图片上传
*
* @param multiReq
* @return
* @throws Exception
*/
@PostMapping(value = "/awsImgUpload", consumes = "multipart/*", headers = "content-type=multipart/form-data")
@ApiOperation("上传图片")
public ResultData awsImgUpload(@RequestParam("file") MultipartFile multiReq
, @RequestParam Map<String, String> param) {
logger.info("[" + getIpAddr() + "] UploadController::awsImgUpload");


long size = multiReq.getSize();
final long length = 2097152;
if (size > length) {
return new ResultData(ErrorCode.PICTURE_SIZE_EXCEED);
}

String fileFormat = "";
try {
int dot = multiReq.getOriginalFilename().lastIndexOf('.');
if (dot >= 0) {
fileFormat = multiReq.getOriginalFilename().substring(dot, multiReq.getOriginalFilename().length());
}

return new ResultData(fileFormat);

} catch (Exception e) {
logger.error("解析图片",e);
return new ResultData(ErrorCode.PICTURE_ANALYZING_ERROR);
}
}


}

+ 1
- 1
mlToutiaoOpen/src/main/java/com/iformall/utils/UrlCheck.java View File

@@ -7,7 +7,7 @@ public class UrlCheck {

public static boolean checkUrl(String url) {
return url.contains("upload_material")
||url.contains("awsFileUpload")
|| url.contains("awsFileUpload")
|| url.contains("awsFilesUpload")
|| url.contains("wxMsgCallback")
|| url.contains("notify");


Loading…
Cancel
Save