|
@ -6,11 +6,13 @@ import com.yihu.wlyy.entity.wechat.WechatTag;
|
|
|
import com.yihu.wlyy.repository.dict.SystemDictDao;
|
|
|
import com.yihu.wlyy.repository.wechat.WechatTagDao;
|
|
|
import com.yihu.wlyy.util.HttpUtil;
|
|
|
import net.sf.json.JSONArray;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
@ -47,7 +49,7 @@ public class WeiXinTagUtil {
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 根据openID给用户打标签,并且同步更新用户表
|
|
|
* 根据openID给用户打标签,
|
|
|
*
|
|
|
* @param openIds
|
|
|
* @param tagId
|
|
@ -78,7 +80,86 @@ public class WeiXinTagUtil {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据openID给用户取消标签,并且同步更新用户表
|
|
|
* 根据openID给用户打标签,
|
|
|
*
|
|
|
* @param openid
|
|
|
* @param tagId
|
|
|
* @return
|
|
|
*/
|
|
|
public String addTagWithOpenid(String openid, Integer tagId) {
|
|
|
try {
|
|
|
net.sf.json.JSONObject params = new net.sf.json.JSONObject();
|
|
|
net.sf.json.JSONArray ja = new JSONArray();
|
|
|
ja.add(openid);
|
|
|
params.put("openid_list", ja);
|
|
|
params.put("tagid", tagId);
|
|
|
String result = httpUtil.sendPost(add_user_tag + weiXinAccessTokenUtils.getAccessToken(), params.toString());
|
|
|
|
|
|
net.sf.json.JSONObject resultJson = net.sf.json.JSONObject.fromObject(result);
|
|
|
|
|
|
if (resultJson.containsKey("errcode")) {
|
|
|
Integer status = resultJson.getInt("errcode");
|
|
|
if (status != 0) {
|
|
|
throw new Exception("创建失败," + result);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage());
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据openID给用户打标签,
|
|
|
*
|
|
|
* @param openid
|
|
|
* @param hospital
|
|
|
* @return
|
|
|
*/
|
|
|
public String addTagWithOpenid(String openid, String hospital) {
|
|
|
try {
|
|
|
if (!StringUtils.isEmpty(hospital)) {
|
|
|
String town=hospital.substring(0,6);
|
|
|
//根据机构获取tagId
|
|
|
WechatTag tagId = wechatTagDao.findByTownCode(town);
|
|
|
if (tagId != null) {
|
|
|
return addTagWithOpenid(openid, tagId.getTagId());
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage());
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据openID给用户取消标签,
|
|
|
*
|
|
|
* @param openid
|
|
|
* @param hospital
|
|
|
* @return
|
|
|
*/
|
|
|
public String deleteTagWithOpenid(String openid, String hospital) {
|
|
|
try {
|
|
|
if (!StringUtils.isEmpty(hospital)) {
|
|
|
String town=hospital.substring(0,6);
|
|
|
//根据机构获取tagId
|
|
|
WechatTag tagId = wechatTagDao.findByTownCode(town);
|
|
|
if (tagId != null) {
|
|
|
return deleteTagWithOpenid(openid, tagId.getTagId());
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage());
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
/**
|
|
|
* 根据openID给用户取消标签,
|
|
|
*
|
|
|
* @param openIds
|
|
|
* @param tagId
|
|
@ -107,7 +188,37 @@ public class WeiXinTagUtil {
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
/**
|
|
|
* 根据openID给用户取消标签,
|
|
|
*
|
|
|
* @param openIds
|
|
|
* @param tagId
|
|
|
* @return
|
|
|
*/
|
|
|
public String deleteTagWithOpenid(String openIds, Integer tagId) {
|
|
|
try {
|
|
|
net.sf.json.JSONObject params = new net.sf.json.JSONObject();
|
|
|
net.sf.json.JSONArray ja=new JSONArray();
|
|
|
ja.add(openIds);
|
|
|
params.put("openid_list", ja);
|
|
|
params.put("tagid", tagId);
|
|
|
String result = httpUtil.sendPost(delete_user_tag + weiXinAccessTokenUtils.getAccessToken(), params.toString());
|
|
|
|
|
|
net.sf.json.JSONObject resultJson = net.sf.json.JSONObject.fromObject(result);
|
|
|
|
|
|
if (resultJson.containsKey("errcode")) {
|
|
|
Integer status = resultJson.getInt("errcode");
|
|
|
if (status != 0) {
|
|
|
throw new Exception("创建失败," + result);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage());
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
/**
|
|
|
* 获取用户身上的标签列表
|
|
|
*
|