提交 529c12dc 编写于 作者: L leon.li

transfer weixin parameters to utf8

上级 82357c6e
......@@ -6,6 +6,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
......@@ -190,9 +191,15 @@ public class DefaultMailImpl implements MailSMS, Initializable, LogEnabled {
@Override
public boolean sendWeiXin(String title, String content, String domain, String weixins) {
String urlParameters = "domain=" + domain + "&email=" + weixins + "&title=" + title + "&content=" + content;
String rawParameters = "domain=" + domain + "&email=" + weixins + "&title=" + title + "&content=" + content;
String urlParameters = null;
Cat.logEvent("WeiXinSend", "sendstart", Event.SUCCESS, "begin");
try {
urlParameters = URLEncoder.encode(rawParameters, "UTF-8");
} catch (UnsupportedEncodingException e) {
Cat.logError("transfer weixin parameters error:" + rawParameters, e);
return false;
}
try {
HttpURLConnection connection = (HttpURLConnection) new URL(WEIXIN_URL).openConnection();
......@@ -218,31 +225,27 @@ public class DefaultMailImpl implements MailSMS, Initializable, LogEnabled {
reader.close();
String responseText = builder.toString();
if (responseText.equals(SUCCESS_TEXT)) {
Cat.logEvent("WeiXinSend", "send_success", Event.SUCCESS, "send success:" + urlParameters + " "
Cat.logEvent("WeiXinSend", "send_success", Event.SUCCESS, "send success:" + rawParameters + " "
+ responseText);
return true;
} else {
Cat.logEvent("WeiXinSend", "send_fail", Event.SUCCESS, "send fail:" + urlParameters + " " + responseText);
Cat.logEvent("WeiXinSend", "send_fail", Event.SUCCESS, "send fail:" + rawParameters + " " + responseText);
return false;
}
} else {
Cat.logEvent("WeiXinSend", "network_fail", Event.SUCCESS, "network fail:" + urlParameters);
Cat.logEvent("WeiXinSend", "network_fail", Event.SUCCESS, "network fail:" + rawParameters);
return false;
}
} catch (Exception ex) {
Cat.logEvent("WeiXinSend", "error", Event.SUCCESS, "error:" + urlParameters);
Cat.logError("send weixin error:" + urlParameters, ex);
Cat.logEvent("WeiXinSend", "error", Event.SUCCESS, "error:" + rawParameters);
Cat.logError("send weixin error:" + rawParameters, ex);
return false;
}
}
public static void main(String[] args) {
boolean result = new DefaultMailImpl().sendWeiXin("test", "test", "test", "tianwen.zhou@dianping.com");
}
public static class Item {
private String m_title;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册