| @@ -1,9 +1,23 @@ | |||||
| package me.chanjar.weixin.mp.api.impl; | package me.chanjar.weixin.mp.api.impl; | ||||
| import java.io.IOException; | |||||
| import org.apache.http.HttpHost; | |||||
| import org.apache.http.client.config.RequestConfig; | |||||
| import org.apache.http.client.methods.CloseableHttpResponse; | |||||
| import org.apache.http.client.methods.HttpGet; | |||||
| import org.apache.http.conn.ssl.DefaultHostnameVerifier; | |||||
| import org.apache.http.conn.ssl.SSLConnectionSocketFactory; | |||||
| import org.apache.http.impl.client.BasicResponseHandler; | |||||
| import org.apache.http.impl.client.CloseableHttpClient; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import com.google.gson.JsonArray; | import com.google.gson.JsonArray; | ||||
| import com.google.gson.JsonElement; | import com.google.gson.JsonElement; | ||||
| import com.google.gson.JsonObject; | import com.google.gson.JsonObject; | ||||
| import com.google.gson.JsonParser; | import com.google.gson.JsonParser; | ||||
| import me.chanjar.weixin.common.bean.WxAccessToken; | import me.chanjar.weixin.common.bean.WxAccessToken; | ||||
| import me.chanjar.weixin.common.bean.WxJsapiSignature; | import me.chanjar.weixin.common.bean.WxJsapiSignature; | ||||
| import me.chanjar.weixin.common.bean.result.WxError; | import me.chanjar.weixin.common.bean.result.WxError; | ||||
| @@ -12,22 +26,38 @@ import me.chanjar.weixin.common.session.StandardSessionManager; | |||||
| import me.chanjar.weixin.common.session.WxSessionManager; | import me.chanjar.weixin.common.session.WxSessionManager; | ||||
| import me.chanjar.weixin.common.util.RandomUtils; | import me.chanjar.weixin.common.util.RandomUtils; | ||||
| import me.chanjar.weixin.common.util.crypto.SHA1; | import me.chanjar.weixin.common.util.crypto.SHA1; | ||||
| import me.chanjar.weixin.common.util.http.*; | |||||
| import me.chanjar.weixin.mp.api.*; | |||||
| import me.chanjar.weixin.mp.bean.*; | |||||
| import me.chanjar.weixin.mp.bean.result.*; | |||||
| import org.apache.http.HttpHost; | |||||
| import org.apache.http.client.config.RequestConfig; | |||||
| import org.apache.http.client.methods.CloseableHttpResponse; | |||||
| import org.apache.http.client.methods.HttpGet; | |||||
| import org.apache.http.conn.ssl.DefaultHostnameVerifier; | |||||
| import org.apache.http.conn.ssl.SSLConnectionSocketFactory; | |||||
| import org.apache.http.impl.client.BasicResponseHandler; | |||||
| import org.apache.http.impl.client.CloseableHttpClient; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import java.io.IOException; | |||||
| import me.chanjar.weixin.common.util.http.ApacheHttpClientBuilder; | |||||
| import me.chanjar.weixin.common.util.http.DefaultApacheHttpClientBuilder; | |||||
| import me.chanjar.weixin.common.util.http.RequestExecutor; | |||||
| import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor; | |||||
| import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor; | |||||
| import me.chanjar.weixin.common.util.http.URIUtil; | |||||
| import me.chanjar.weixin.mp.api.WxMpCardService; | |||||
| import me.chanjar.weixin.mp.api.WxMpConfigStorage; | |||||
| import me.chanjar.weixin.mp.api.WxMpDataCubeService; | |||||
| import me.chanjar.weixin.mp.api.WxMpKefuService; | |||||
| import me.chanjar.weixin.mp.api.WxMpMaterialService; | |||||
| import me.chanjar.weixin.mp.api.WxMpMenuService; | |||||
| import me.chanjar.weixin.mp.api.WxMpPayService; | |||||
| import me.chanjar.weixin.mp.api.WxMpQrcodeService; | |||||
| import me.chanjar.weixin.mp.api.WxMpService; | |||||
| import me.chanjar.weixin.mp.api.WxMpStoreService; | |||||
| import me.chanjar.weixin.mp.api.WxMpUserBlacklistService; | |||||
| import me.chanjar.weixin.mp.api.WxMpUserService; | |||||
| import me.chanjar.weixin.mp.api.WxMpUserTagService; | |||||
| import me.chanjar.weixin.mp.bean.WxMpIndustry; | |||||
| import me.chanjar.weixin.mp.bean.WxMpMassNews; | |||||
| import me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage; | |||||
| import me.chanjar.weixin.mp.bean.WxMpMassPreviewMessage; | |||||
| import me.chanjar.weixin.mp.bean.WxMpMassTagMessage; | |||||
| import me.chanjar.weixin.mp.bean.WxMpMassVideo; | |||||
| import me.chanjar.weixin.mp.bean.WxMpSemanticQuery; | |||||
| import me.chanjar.weixin.mp.bean.WxMpTemplateMessage; | |||||
| import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult; | |||||
| import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult; | |||||
| import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; | |||||
| import me.chanjar.weixin.mp.bean.result.WxMpSemanticQueryResult; | |||||
| import me.chanjar.weixin.mp.bean.result.WxMpUser; | |||||
| public class WxMpServiceImpl implements WxMpService { | public class WxMpServiceImpl implements WxMpService { | ||||
| @@ -178,35 +208,35 @@ public class WxMpServiceImpl implements WxMpService { | |||||
| @Override | @Override | ||||
| public WxMpMassUploadResult massNewsUpload(WxMpMassNews news) throws WxErrorException { | public WxMpMassUploadResult massNewsUpload(WxMpMassNews news) throws WxErrorException { | ||||
| String url = "https://api.weixin.qq.com/cgi-bin/media/uploadnews"; | String url = "https://api.weixin.qq.com/cgi-bin/media/uploadnews"; | ||||
| String responseContent = execute(new SimplePostRequestExecutor(), url, news.toJson()); | |||||
| String responseContent = this.post(url, news.toJson()); | |||||
| return WxMpMassUploadResult.fromJson(responseContent); | return WxMpMassUploadResult.fromJson(responseContent); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public WxMpMassUploadResult massVideoUpload(WxMpMassVideo video) throws WxErrorException { | public WxMpMassUploadResult massVideoUpload(WxMpMassVideo video) throws WxErrorException { | ||||
| String url = "https://api.weixin.qq.com/cgi-bin/media/uploadvideo"; | String url = "https://api.weixin.qq.com/cgi-bin/media/uploadvideo"; | ||||
| String responseContent = execute(new SimplePostRequestExecutor(), url, video.toJson()); | |||||
| String responseContent = this.post(url, video.toJson()); | |||||
| return WxMpMassUploadResult.fromJson(responseContent); | return WxMpMassUploadResult.fromJson(responseContent); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public WxMpMassSendResult massGroupMessageSend(WxMpMassTagMessage message) throws WxErrorException { | public WxMpMassSendResult massGroupMessageSend(WxMpMassTagMessage message) throws WxErrorException { | ||||
| String url = "https://api.weixin.qq.com/cgi-bin/message/mass/sendall"; | String url = "https://api.weixin.qq.com/cgi-bin/message/mass/sendall"; | ||||
| String responseContent = execute(new SimplePostRequestExecutor(), url, message.toJson()); | |||||
| String responseContent = this.post(url, message.toJson()); | |||||
| return WxMpMassSendResult.fromJson(responseContent); | return WxMpMassSendResult.fromJson(responseContent); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public WxMpMassSendResult massOpenIdsMessageSend(WxMpMassOpenIdsMessage message) throws WxErrorException { | public WxMpMassSendResult massOpenIdsMessageSend(WxMpMassOpenIdsMessage message) throws WxErrorException { | ||||
| String url = "https://api.weixin.qq.com/cgi-bin/message/mass/send"; | String url = "https://api.weixin.qq.com/cgi-bin/message/mass/send"; | ||||
| String responseContent = execute(new SimplePostRequestExecutor(), url, message.toJson()); | |||||
| String responseContent = this.post(url, message.toJson()); | |||||
| return WxMpMassSendResult.fromJson(responseContent); | return WxMpMassSendResult.fromJson(responseContent); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public WxMpMassSendResult massMessagePreview(WxMpMassPreviewMessage wxMpMassPreviewMessage) throws Exception { | public WxMpMassSendResult massMessagePreview(WxMpMassPreviewMessage wxMpMassPreviewMessage) throws Exception { | ||||
| String url = "https://api.weixin.qq.com/cgi-bin/message/mass/preview"; | String url = "https://api.weixin.qq.com/cgi-bin/message/mass/preview"; | ||||
| String responseContent = execute(new SimplePostRequestExecutor(), url, wxMpMassPreviewMessage.toJson()); | |||||
| String responseContent = this.post(url, wxMpMassPreviewMessage.toJson()); | |||||
| return WxMpMassSendResult.fromJson(responseContent); | return WxMpMassSendResult.fromJson(responseContent); | ||||
| } | } | ||||
| @@ -216,7 +246,7 @@ public class WxMpServiceImpl implements WxMpService { | |||||
| JsonObject o = new JsonObject(); | JsonObject o = new JsonObject(); | ||||
| o.addProperty("action", "long2short"); | o.addProperty("action", "long2short"); | ||||
| o.addProperty("long_url", long_url); | o.addProperty("long_url", long_url); | ||||
| String responseContent = execute(new SimplePostRequestExecutor(), url, o.toString()); | |||||
| String responseContent = this.post(url, o.toString()); | |||||
| JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent); | JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent); | ||||
| return tmpJsonElement.getAsJsonObject().get("short_url").getAsString(); | return tmpJsonElement.getAsJsonObject().get("short_url").getAsString(); | ||||
| } | } | ||||
| @@ -240,20 +270,20 @@ public class WxMpServiceImpl implements WxMpService { | |||||
| throw new IllegalArgumentException("industry id is empty"); | throw new IllegalArgumentException("industry id is empty"); | ||||
| } | } | ||||
| String url = "https://api.weixin.qq.com/cgi-bin/template/api_set_industry"; | String url = "https://api.weixin.qq.com/cgi-bin/template/api_set_industry"; | ||||
| return execute(new SimplePostRequestExecutor(), url, wxMpIndustry.toJson()); | |||||
| return this.post(url, wxMpIndustry.toJson()); | |||||
| } | } | ||||
| @Override | @Override | ||||
| public WxMpIndustry getIndustry() throws WxErrorException { | public WxMpIndustry getIndustry() throws WxErrorException { | ||||
| String url = "https://api.weixin.qq.com/cgi-bin/template/get_industry"; | String url = "https://api.weixin.qq.com/cgi-bin/template/get_industry"; | ||||
| String responseContent = execute(new SimpleGetRequestExecutor(), url, null); | |||||
| String responseContent = this.get(url, null); | |||||
| return WxMpIndustry.fromJson(responseContent); | return WxMpIndustry.fromJson(responseContent); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public WxMpSemanticQueryResult semanticQuery(WxMpSemanticQuery semanticQuery) throws WxErrorException { | public WxMpSemanticQueryResult semanticQuery(WxMpSemanticQuery semanticQuery) throws WxErrorException { | ||||
| String url = "https://api.weixin.qq.com/semantic/semproxy/search"; | String url = "https://api.weixin.qq.com/semantic/semproxy/search"; | ||||
| String responseContent = execute(new SimplePostRequestExecutor(), url, semanticQuery.toJson()); | |||||
| String responseContent = this.post(url, semanticQuery.toJson()); | |||||
| return WxMpSemanticQueryResult.fromJson(responseContent); | return WxMpSemanticQueryResult.fromJson(responseContent); | ||||
| } | } | ||||