@ -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 ;
}
}