Commit 19f14c80 by 墨竹

fix:欢迎语发送修改

parent f8ce4929
...@@ -18,13 +18,13 @@ public class MemberUnionidWechatAccountQDTO implements Serializable { ...@@ -18,13 +18,13 @@ public class MemberUnionidWechatAccountQDTO implements Serializable {
*/ */
private String unionid; private String unionid;
/** /**
* 导购id * openId
*/ */
private String clerkId; private String openId;
/** /**
* 微信企业id * 参数
*/ */
private String wxEnterpriseId; private String sceneStr;
public String getEnterpriseId() { public String getEnterpriseId() {
return enterpriseId; return enterpriseId;
...@@ -42,19 +42,19 @@ public class MemberUnionidWechatAccountQDTO implements Serializable { ...@@ -42,19 +42,19 @@ public class MemberUnionidWechatAccountQDTO implements Serializable {
this.unionid = unionid; this.unionid = unionid;
} }
public String getClerkId() { public String getOpenId() {
return clerkId; return openId;
} }
public void setClerkId(String clerkId) { public void setOpenId(String openId) {
this.clerkId = clerkId; this.openId = openId;
} }
public String getWxEnterpriseId() { public String getSceneStr() {
return wxEnterpriseId; return sceneStr;
} }
public void setWxEnterpriseId(String wxEnterpriseId) { public void setSceneStr(String sceneStr) {
this.wxEnterpriseId = wxEnterpriseId; this.sceneStr = sceneStr;
} }
} }
...@@ -14,7 +14,9 @@ import com.gic.clerk.api.service.PowerService; ...@@ -14,7 +14,9 @@ import com.gic.clerk.api.service.PowerService;
import com.gic.commons.util.DateUtil; import com.gic.commons.util.DateUtil;
import com.gic.commons.util.EntityUtil; import com.gic.commons.util.EntityUtil;
import com.gic.commons.util.GICMQClientUtil; import com.gic.commons.util.GICMQClientUtil;
import com.gic.enterprise.api.dto.EnterpriseDTO;
import com.gic.enterprise.api.dto.StoreDTO; import com.gic.enterprise.api.dto.StoreDTO;
import com.gic.enterprise.api.service.EnterpriseService;
import com.gic.enterprise.api.service.StoreService; import com.gic.enterprise.api.service.StoreService;
import com.gic.haoban.app.customer.dto.ChildDTO; import com.gic.haoban.app.customer.dto.ChildDTO;
import com.gic.haoban.app.customer.dto.CustomerDTO; import com.gic.haoban.app.customer.dto.CustomerDTO;
...@@ -53,6 +55,7 @@ import com.gic.wechat.api.dto.qywx.welcome.QywxImageExternalBaseDTO; ...@@ -53,6 +55,7 @@ import com.gic.wechat.api.dto.qywx.welcome.QywxImageExternalBaseDTO;
import com.gic.wechat.api.dto.qywx.welcome.QywxMiniprogramExternalBaseDTO; import com.gic.wechat.api.dto.qywx.welcome.QywxMiniprogramExternalBaseDTO;
import com.gic.wechat.api.dto.qywx.welcome.QywxWelcomeMsgDTO; import com.gic.wechat.api.dto.qywx.welcome.QywxWelcomeMsgDTO;
import com.gic.wechat.api.enums.QywxMediaTypeEnum; import com.gic.wechat.api.enums.QywxMediaTypeEnum;
import com.gic.wechat.api.service.fwh.WeixinBaseFunService;
import com.gic.wechat.api.service.qywx.QywxSuiteApiService; import com.gic.wechat.api.service.qywx.QywxSuiteApiService;
import com.gic.wechat.api.service.qywx.QywxUserApiService; import com.gic.wechat.api.service.qywx.QywxUserApiService;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
...@@ -62,6 +65,9 @@ import org.apache.commons.io.IOUtils; ...@@ -62,6 +65,9 @@ import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.redisson.api.RRateLimiter;
import org.redisson.api.RateIntervalUnit;
import org.redisson.api.RateType;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -128,6 +134,10 @@ public class MemberUnionidRelatedApiServiceImpl implements MemberUnionidRelatedA ...@@ -128,6 +134,10 @@ public class MemberUnionidRelatedApiServiceImpl implements MemberUnionidRelatedA
private WxApplicationMapper wxApplicationMapper; private WxApplicationMapper wxApplicationMapper;
@Autowired @Autowired
private MemberApiService memberApiService; private MemberApiService memberApiService;
@Autowired
private WeixinBaseFunService weixinBaseFunService;
@Autowired
private EnterpriseService enterpriseService;
@Override @Override
public void dealQywxExternalUser(String params) { public void dealQywxExternalUser(String params) {
...@@ -425,7 +435,7 @@ public class MemberUnionidRelatedApiServiceImpl implements MemberUnionidRelatedA ...@@ -425,7 +435,7 @@ public class MemberUnionidRelatedApiServiceImpl implements MemberUnionidRelatedA
exsitDTO.setStatusFlag(1); exsitDTO.setStatusFlag(1);
externalClerkRelatedService.update(exsitDTO); externalClerkRelatedService.update(exsitDTO);
} }
sendWelcome(dto, wxEnterpriseId,enterpriseId,staffId, false); sendWelcome(dto, wxEnterpriseId, enterpriseId, staffId, false);
//同步好友标签 //同步好友标签
pushTagSync(memberId, wxEnterpriseId, enterpriseId); pushTagSync(memberId, wxEnterpriseId, enterpriseId);
//回调给会员 //回调给会员
...@@ -436,8 +446,7 @@ public class MemberUnionidRelatedApiServiceImpl implements MemberUnionidRelatedA ...@@ -436,8 +446,7 @@ public class MemberUnionidRelatedApiServiceImpl implements MemberUnionidRelatedA
private static byte[] getFileByte(String url) { private static byte[] getFileByte(String url) {
try { try {
InputStream in = new URL(url).openStream(); InputStream in = new URL(url).openStream();
byte[] data = IOUtils.toByteArray(in); return IOUtils.toByteArray(in);
return data;
} catch (Exception e) { } catch (Exception e) {
log.info("【异常】" + e.getMessage(), e); log.info("【异常】" + e.getMessage(), e);
} }
...@@ -494,6 +503,7 @@ public class MemberUnionidRelatedApiServiceImpl implements MemberUnionidRelatedA ...@@ -494,6 +503,7 @@ public class MemberUnionidRelatedApiServiceImpl implements MemberUnionidRelatedA
/** /**
* 发送欢迎语 * 发送欢迎语
*
* @param dto * @param dto
* @param wxEnterpriseId * @param wxEnterpriseId
* @param enterpriseId * @param enterpriseId
...@@ -514,10 +524,28 @@ public class MemberUnionidRelatedApiServiceImpl implements MemberUnionidRelatedA ...@@ -514,10 +524,28 @@ public class MemberUnionidRelatedApiServiceImpl implements MemberUnionidRelatedA
return; return;
} }
String externalName = dto.getExternalName(); String externalName = dto.getExternalName();
//内容
String content = tabWelcome.getWelcomeContent().replaceAll("<微信昵称>", externalName); String content = tabWelcome.getWelcomeContent().replaceAll("<微信昵称>", externalName);
QywxWelcomeMsgDTO qywxWelcomeMsgDTO = new QywxWelcomeMsgDTO(); QywxWelcomeMsgDTO qywxWelcomeMsgDTO = new QywxWelcomeMsgDTO();
qywxWelcomeMsgDTO.setText(content); qywxWelcomeMsgDTO.setText(content);
//欢迎语类型
List<QywxExternalMessageBaseDTO> attachments = new ArrayList<>(); List<QywxExternalMessageBaseDTO> attachments = new ArrayList<>();
// TODO: 2022/2/9 带参数的公众号二维码等配置
if (false) {
//带参数的公众号二维码
EnterpriseDTO enterpriseDTO = enterpriseService.getEnterpriseById(enterpriseId);
String sceneStr = "QWHY_" + relationKey;
//7天失效
String temporaryQRcodeURL = weixinBaseFunService.getTemporaryQRcodeURL(enterpriseDTO.getAppkey(), sceneStr, 604800);
JSONResponse jp = qywxSuiteApiService.uploadMedia(wxEnterpriseDTO.getCorpid(), config.getWxSuiteid(), getFileByte(temporaryQRcodeURL),sceneStr, QywxMediaTypeEnum.IMAGE.getCode());
log.info("欢迎语发送带参数的公众号二维码返回:{}", JSON.toJSONString(jp));
if (jp.getErrorCode() == 0) {
QywxImageExternalBaseDTO qywxImageExternalBaseDTO = new QywxImageExternalBaseDTO();
qywxImageExternalBaseDTO.setMediaId(jp.getResult().toString());
attachments.add(qywxImageExternalBaseDTO);
}
} else {
//小程序
//发送小程序 //发送小程序
if (sendApp) { if (sendApp) {
log.info("发送小程序:{}", wxEnterpriseId); log.info("发送小程序:{}", wxEnterpriseId);
...@@ -546,6 +574,7 @@ public class MemberUnionidRelatedApiServiceImpl implements MemberUnionidRelatedA ...@@ -546,6 +574,7 @@ public class MemberUnionidRelatedApiServiceImpl implements MemberUnionidRelatedA
attachments.add(qywxImageExternalBaseDTO); attachments.add(qywxImageExternalBaseDTO);
} }
} }
}
if (CollectionUtils.isNotEmpty(attachments)) { if (CollectionUtils.isNotEmpty(attachments)) {
qywxWelcomeMsgDTO.setAttachments(attachments); qywxWelcomeMsgDTO.setAttachments(attachments);
} }
...@@ -1538,7 +1567,7 @@ public class MemberUnionidRelatedApiServiceImpl implements MemberUnionidRelatedA ...@@ -1538,7 +1567,7 @@ public class MemberUnionidRelatedApiServiceImpl implements MemberUnionidRelatedA
String clerkId = dto.getClerkId(); String clerkId = dto.getClerkId();
String selfExternalUserId = dto.getSelfExternalUserId(); String selfExternalUserId = dto.getSelfExternalUserId();
if (StringUtils.isAnyBlank(wxUserId, selfExternalUserId, wxEnterpriseId, name, createTime, externalUserId, storeId, enterpriseId, staffId, clerkId)) { if (StringUtils.isAnyBlank(wxUserId, selfExternalUserId, wxEnterpriseId, name, createTime, externalUserId, storeId, enterpriseId, staffId, clerkId)) {
log.error("参数不对:{}",JSON.toJSONString(dto)); log.error("参数不对:{}", JSON.toJSONString(dto));
return "参数不对"; return "参数不对";
} }
String relationKey = SecureUtil.md5(staffId + externalUserId); String relationKey = SecureUtil.md5(staffId + externalUserId);
...@@ -1689,11 +1718,48 @@ public class MemberUnionidRelatedApiServiceImpl implements MemberUnionidRelatedA ...@@ -1689,11 +1718,48 @@ public class MemberUnionidRelatedApiServiceImpl implements MemberUnionidRelatedA
@Override @Override
public void addMemberUnionidWechatAccount(String res) { public void addMemberUnionidWechatAccount(String res) {
log.info("通过查询unionid关联导购对外联系人id接口,res:{}", res);
JSONObject jsonObject = JSON.parseObject(res);
String unionid = jsonObject.getString("unionid");
String openid = jsonObject.getString("openid");
String enterpriseId = jsonObject.getString("enterpriseId");
List<TabHaobanWxEnterprise> tabHaobanWxEnterprises = wxEnterpriseRelatedService.listByEnterpriseId(enterpriseId);
if (CollectionUtils.isEmpty(tabHaobanWxEnterprises)) {
log.error("企业为空");
return;
}
RRateLimiter rateLimiter = RedisUtil.getRedisClient().getRateLimiter("member:weChat:add:limit");
// 每1小时产生10000个令牌
rateLimiter.trySetRate(RateType.OVERALL, 9500, 1, RateIntervalUnit.HOURS);
for (TabHaobanWxEnterprise tabHaobanWxEnterpris : tabHaobanWxEnterprises) {
if (!rateLimiter.tryAcquire(1)) {
log.error("请求unionidToExternalUserid3rd超过限制,丢入消息队列,重新消费");
GicMQClient clientInstance = GICMQClientUtil.getClientInstance();
try {
clientInstance.sendMessage("addMemberUnionidWechatAccountMq", res, 60 * 60);
} catch (Exception e) {
log.info("addMemberUnionidWechatAccount 发送失败:{}", e.getMessage(), e);
}
return;
}
List<UnionidToExternalUseridDTO> unionidToExternalUseridDTOS = qywxUserApiService.unionidToExternalUserid3rd(unionid, openid, tabHaobanWxEnterpris.getCorpid(), config.getWxSuiteid());
if (CollectionUtils.isEmpty(unionidToExternalUseridDTOS)) {
log.error("请求unionidToExternalUserid3rd返回为空");
return;
}
for (UnionidToExternalUseridDTO unionidToExternalUseridDTO : unionidToExternalUseridDTOS) {
unionidToExternalUseridDTO.getExternalUserid();
}
}
} }
@Override @Override
public ServiceResponse<Boolean> addMemberUnionidWechatAccountByClerk(MemberUnionidWechatAccountQDTO memberUnionidWechatAccountQDTO) { public ServiceResponse<Boolean> addMemberUnionidWechatAccountByClerk(MemberUnionidWechatAccountQDTO memberUnionidWechatAccountQDTO) {
return null; return null;
} }
} }
...@@ -144,4 +144,6 @@ ...@@ -144,4 +144,6 @@
<dubbo:reference interface="com.gic.enterprise.api.service.AuthorizeService" id="authorizeService"/> <dubbo:reference interface="com.gic.enterprise.api.service.AuthorizeService" id="authorizeService"/>
<dubbo:reference id="quartzService" interface="com.gic.quartz.api.service.QuartzService" timeout="10000"/> <dubbo:reference id="quartzService" interface="com.gic.quartz.api.service.QuartzService" timeout="10000"/>
<dubbo:reference id="memberApiService" interface="com.gic.member.api.service.MemberApiService" timeout="10000"/> <dubbo:reference id="memberApiService" interface="com.gic.member.api.service.MemberApiService" timeout="10000"/>
<dubbo:reference id="weixinBaseFunService" interface="com.gic.wechat.api.service.fwh.WeixinBaseFunService" timeout="10000"/>
</beans> </beans>
\ No newline at end of file
...@@ -189,7 +189,7 @@ ...@@ -189,7 +189,7 @@
from tab_haoban_miniprogram_setting from tab_haoban_miniprogram_setting
where wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR} where wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR}
and enterprise_id=#{enterpriseId} and enterprise_id=#{enterpriseId}
and status_flag=1 and status_flag=1 order by create_time desc limit 1
</select> </select>
<select id="listMiniprogramSetting" resultMap="BaseResultMap"> <select id="listMiniprogramSetting" resultMap="BaseResultMap">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment