master
wangning 7 years ago
parent adbfe6ca31
commit 9126519dcf

@ -107,7 +107,6 @@ import com.github.miemiedev.mybatis.paginator.domain.Order;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.github.miemiedev.mybatis.paginator.domain.PageList;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.RandomStringUtils;
@ -145,7 +144,6 @@ import java.io.OutputStream;
import java.math.BigDecimal;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
@ -581,7 +579,7 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
}
}
try {
JSONObject res = addClientToMailList(partner);
mailGunService.addClientToMailList(partner);
}catch (Exception e){
logger.error("邮件列表添加成员失败",e);
}
@ -620,6 +618,9 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
}
}
clientMapper.update(updateInfo);
if(client.getString("contact_email").equals(updateInfo.getString("contact_email"))){
mailGunService.updateClientOfMailList(updateInfo,client);
}
clientInfoCacheSupport.clearClientCache(clientId);
}
@ -3342,71 +3343,4 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
checkOrgPermission(manager, client);
return logClientSubMerchantIdMapper.listLogsByClientId(client.getInteger("client_id"));
}
public JSONObject addClientToMailList(JSONObject client){
String createUrl = "https://api.mailgun.net/v3/lists/1551130722@sandbox08f2aafe29184b08b38322106c8bd4f5.mailgun.org/members";
JSONObject vars = new JSONObject();
vars.put("client_moniker",client.getString("client_moniker"));
vars.put("short_name",client.getString("short_name"));
vars.put("bd_user_name",client.getString("bd_user_name"));
vars.put("company_phone",client.getString("company_phone"));
vars.put("description",client.getString("description"));
HttpRequestGenerator generator = new HttpRequestGenerator(createUrl, RequestMethod.POST)
.addHeader("Authorization",getHeader())
.addQueryString("subscribed","true")
.addQueryString("address",client.getString("contact_email"))
.addQueryString("name",client.getString("company_name"))
.addQueryString("description","merchant")
.addQueryString("vars",vars.toJSONString());
HttpRequestResult res = null;
try {
res = generator.execute();
} catch (URISyntaxException e) {
e.printStackTrace();
}
try {
return res.getResponseContentJSONObj();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
public JSONObject updateClientOfMailList(JSONObject newClient,JSONObject oldClient){
String createUrl = "https://api.mailgun.net/v3/lists/1551130722@sandbox08f2aafe29184b08b38322106c8bd4f5.mailgun.org/members/"+oldClient.getString("contact_email");
JSONObject vars = new JSONObject();
vars.put("client_moniker",newClient.getString("client_moniker"));
vars.put("short_name",newClient.getString("short_name"));
vars.put("bd_user_name",newClient.getString("bd_user_name"));
vars.put("company_phone",newClient.getString("company_phone"));
vars.put("description",newClient.getString("description"));
HttpRequestGenerator generator = new HttpRequestGenerator(createUrl, RequestMethod.PUT).addHeader("Authorization",getHeader())
.addQueryString("address",newClient.getString("contact_email"))
.addQueryString("name",newClient.getString("company_name"))
.addQueryString("vars",vars.toJSONString());
HttpRequestResult res = null;
try {
res = generator.execute();
} catch (URISyntaxException e) {
e.printStackTrace();
}
try {
return res.getResponseContentJSONObj();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
private String getHeader() {
String auth = "api:key-17c2d9f2b569cfc0983320cfb22d3fdc";
byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(Charset.forName("UTF-8")));
String authHeader = "Basic " + new String(encodedAuth);
return authHeader;
}
}

@ -10,4 +10,8 @@ public interface MailGunService {
void dealNotify(String nofityString) throws Exception;
JSONObject sendMail(SendMail sendMail);
JSONObject addClientToMailList(JSONObject client);
JSONObject updateClientOfMailList(JSONObject newClient,JSONObject oldClient);
}

@ -52,6 +52,35 @@ public class MailGunServiceImpl implements MailGunService {
return mailGunClient.sendMail(sendMail);
}
@Override
public JSONObject addClientToMailList(JSONObject client) {
JSONObject result = null;
try {
JSONObject var = new JSONObject();
var.put("client_moniker", client.getString("client_moniker"));
var.put("short_name", client.getString("short_name"));
result = mailGunClient.addListMember(client.getString("contact_email"),"merchants",client.getString("contact_person"),var);
}catch (Exception ignore){
logger.info("add Mail List Failed email:"+client.getString("contact_email")+" client_moniker:"+client.getString("client_moniker"));
}
return result;
}
@Override
public JSONObject updateClientOfMailList(JSONObject newClient, JSONObject oldClient) {
JSONObject result= null;
try {
JSONObject var = new JSONObject();
var.put("client_moniker", newClient.getString("client_moniker"));
var.put("short_name", newClient.getString("short_name"));
result = mailGunClient.updateClientOfMailList(newClient.getString("contact_email"),"merchants",newClient.getString("contact_person"),oldClient.getString("contact_email"),var);
}catch (Exception ignore){
logger.info("Modify Mail List Failed oldEmail:"+oldClient.getString("contact_email")+" client_moniker:"+newClient.getString("client_moniker") + " newEmail:"+newClient.getString("contact_email"));
}
return result;
}
public Map<String, String> getQueryMap(String query) {
String[] params = query.split("&");
Map<String, String> map = new HashMap<>();

Loading…
Cancel
Save