|
@@ -6,6 +6,7 @@ import com.bosshand.virgo.core.model.Customer;
|
|
|
import com.bosshand.virgo.core.utils.CodeCache;
|
|
|
import com.bosshand.virgo.core.utils.StringUtil;
|
|
|
import com.bosshand.virgo.core.utils.WeChatUtil;
|
|
|
+import org.apache.commons.codec.digest.DigestUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -75,4 +76,42 @@ public class CustomerService {
|
|
|
public Customer get(long id) {
|
|
|
return customerDao.get(id);
|
|
|
}
|
|
|
+
|
|
|
+ public int delete(long id) {
|
|
|
+ return customerDao.delete(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getToken(String userId) {
|
|
|
+ JSONObject js = new JSONObject();
|
|
|
+ long timestamp = System.currentTimeMillis() + 30000;
|
|
|
+ String yei = "50abd47112ebe8c5a73f4694c96a49ce";
|
|
|
+ String sign = DigestUtils.md5Hex(userId + timestamp + yei);
|
|
|
+
|
|
|
+ js.put("userId", userId);
|
|
|
+ js.put("timestamp", timestamp);
|
|
|
+ js.put("sign", sign);
|
|
|
+ String s = WeChatUtil.httpPost("https://www.waywish.com/im/user/token/get", js, null);
|
|
|
+ if (StringUtil.notBlank(s)) {
|
|
|
+ String token = JSONObject.parseObject(s).getJSONObject("data").getString("token");
|
|
|
+ return token;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Customer getOrganizationId(long organizationId, long userId) {
|
|
|
+ return customerDao.getOrganizationId(organizationId, userId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public int updateInfo(Customer customer) {
|
|
|
+ Customer c = customerDao.get(customer.getId());
|
|
|
+ String token = getToken(c.getCustomerId());
|
|
|
+ JSONObject js = new JSONObject();
|
|
|
+ js.put("nickname", customer.getNickName());
|
|
|
+ js.put("avatarUrl", customer.getAvatarUrl());
|
|
|
+ String str = WeChatUtil.httpPost("https://www.waywish.com/im/user/update", js, token);
|
|
|
+ log.info("updateCustomerChatUser=" + str);
|
|
|
+ return customerDao.update(customer);
|
|
|
+ }
|
|
|
+
|
|
|
}
|