mirror of
				https://gitee.com/binary/weixin-java-tools.git
				synced 2025-10-31 10:38:42 +08:00 
			
		
		
		
	Merge commit '4da9ea5dd5210674ccc3d20d470d337857182474' into develop
* commit '4da9ea5dd5210674ccc3d20d470d337857182474': 增加临时文件目录配置 增加忽略eclipse本地配置文件目录 fix README
This commit is contained in:
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -15,6 +15,7 @@ hs_err_pid* | |||||||
| target | target | ||||||
| .project | .project | ||||||
| .classpath | .classpath | ||||||
|  | .settings | ||||||
|  |  | ||||||
| sw-pom.xml | sw-pom.xml | ||||||
| *.iml | *.iml | ||||||
|  | |||||||
| @ -7,18 +7,25 @@ import java.io.InputStream; | |||||||
|  |  | ||||||
| public class FileUtils { | public class FileUtils { | ||||||
|  |  | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * 创建临时文件 |    * 创建临时文件 | ||||||
|    * @param inputStream |    * @param inputStream | ||||||
|    * @param name  文件名 |    * @param name  文件名 | ||||||
|    * @param ext   扩展名 |    * @param ext   扩展名 | ||||||
|  |    * @param tmpDirFile   临时文件夹目录 | ||||||
|    * @return |    * @return | ||||||
|    * @throws IOException |    * @throws IOException | ||||||
|    */ |    */ | ||||||
|   public static File createTmpFile(InputStream inputStream, String name, String ext) throws IOException { |   public static File createTmpFile(InputStream inputStream, String name, String ext, File tmpDirFile) throws IOException { | ||||||
|     FileOutputStream fos = null; |     FileOutputStream fos = null; | ||||||
|     try { |     try { | ||||||
|       File tmpFile = File.createTempFile(name, '.' + ext); |       File tmpFile; | ||||||
|  |       if (tmpDirFile == null) { | ||||||
|  |     	  tmpFile = File.createTempFile(name, '.' + ext); | ||||||
|  |       } else { | ||||||
|  |         tmpFile = File.createTempFile(name, '.' + ext, tmpDirFile); | ||||||
|  |       } | ||||||
|       tmpFile.deleteOnExit(); |       tmpFile.deleteOnExit(); | ||||||
|       fos = new FileOutputStream(tmpFile); |       fos = new FileOutputStream(tmpFile); | ||||||
|       int read = 0; |       int read = 0; | ||||||
| @ -44,4 +51,16 @@ public class FileUtils { | |||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   /** | ||||||
|  |    * 创建临时文件 | ||||||
|  |    * @param inputStream | ||||||
|  |    * @param name  文件名 | ||||||
|  |    * @param ext   扩展名 | ||||||
|  |    * @return | ||||||
|  |    * @throws IOException | ||||||
|  |    */ | ||||||
|  |   public static File createTmpFile(InputStream inputStream, String name, String ext) throws IOException { | ||||||
|  |     return createTmpFile(inputStream, name, ext, null); | ||||||
|  |   } | ||||||
|  |    | ||||||
| } | } | ||||||
|  | |||||||
| @ -26,6 +26,18 @@ import java.util.regex.Pattern; | |||||||
|  */ |  */ | ||||||
| public class MediaDownloadRequestExecutor implements RequestExecutor<File, String> { | public class MediaDownloadRequestExecutor implements RequestExecutor<File, String> { | ||||||
| 	 | 	 | ||||||
|  |   private File tmpDirFile; | ||||||
|  |  | ||||||
|  |   public MediaDownloadRequestExecutor() { | ||||||
|  |     super(); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public MediaDownloadRequestExecutor(File tmpDirFile) { | ||||||
|  |     super(); | ||||||
|  |     this.tmpDirFile = tmpDirFile; | ||||||
|  |   } | ||||||
|  |    | ||||||
|  |  | ||||||
|   @Override |   @Override | ||||||
|   public File execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, String queryParam) throws WxErrorException, ClientProtocolException, IOException { |   public File execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, String queryParam) throws WxErrorException, ClientProtocolException, IOException { | ||||||
|     if (queryParam != null) { |     if (queryParam != null) { | ||||||
| @ -59,7 +71,7 @@ public class MediaDownloadRequestExecutor implements RequestExecutor<File, Strin | |||||||
|       return null; |       return null; | ||||||
|     } |     } | ||||||
|     String[] name_ext = fileName.split("\\."); |     String[] name_ext = fileName.split("\\."); | ||||||
|     File localFile = FileUtils.createTmpFile(inputStream, name_ext[0], name_ext[1]); |     File localFile = FileUtils.createTmpFile(inputStream, name_ext[0], name_ext[1], tmpDirFile); | ||||||
|     return localFile; |     return localFile; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  | |||||||
| @ -1,5 +1,7 @@ | |||||||
| package me.chanjar.weixin.cp.api; | package me.chanjar.weixin.cp.api; | ||||||
|  |  | ||||||
|  | import java.io.File; | ||||||
|  |  | ||||||
| import me.chanjar.weixin.common.bean.WxAccessToken; | import me.chanjar.weixin.common.bean.WxAccessToken; | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @ -59,4 +61,6 @@ public interface WxCpConfigStorage { | |||||||
|  |  | ||||||
|   public String getHttp_proxy_password(); |   public String getHttp_proxy_password(); | ||||||
|    |    | ||||||
|  |   public File getTmpDirFile(); | ||||||
|  |  | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,5 +1,7 @@ | |||||||
| package me.chanjar.weixin.cp.api; | package me.chanjar.weixin.cp.api; | ||||||
|  |  | ||||||
|  | import java.io.File; | ||||||
|  |  | ||||||
| import me.chanjar.weixin.common.bean.WxAccessToken; | import me.chanjar.weixin.common.bean.WxAccessToken; | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @ -28,6 +30,8 @@ public class WxCpInMemoryConfigStorage implements WxCpConfigStorage { | |||||||
|   protected volatile String jsapiTicket; |   protected volatile String jsapiTicket; | ||||||
|   protected volatile long jsapiTicketExpiresTime; |   protected volatile long jsapiTicketExpiresTime; | ||||||
|  |  | ||||||
|  |   protected volatile File tmpDirFile; | ||||||
|  |  | ||||||
|   public String getAccessToken() { |   public String getAccessToken() { | ||||||
|     return this.accessToken; |     return this.accessToken; | ||||||
|   } |   } | ||||||
| @ -189,7 +193,16 @@ public class WxCpInMemoryConfigStorage implements WxCpConfigStorage { | |||||||
|         ", http_proxy_password='" + http_proxy_password + '\'' + |         ", http_proxy_password='" + http_proxy_password + '\'' + | ||||||
|         ", jsapiTicket='" + jsapiTicket + '\'' + |         ", jsapiTicket='" + jsapiTicket + '\'' + | ||||||
|         ", jsapiTicketExpiresTime='" + jsapiTicketExpiresTime + '\'' + |         ", jsapiTicketExpiresTime='" + jsapiTicketExpiresTime + '\'' + | ||||||
|  |         ", tmpDirFile='" + tmpDirFile + '\'' + | ||||||
|         '}'; |         '}'; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   public File getTmpDirFile() { | ||||||
|  |     return tmpDirFile; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public void setTmpDirFile(File tmpDirFile) { | ||||||
|  |     this.tmpDirFile = tmpDirFile; | ||||||
|  |   } | ||||||
|  |  | ||||||
| } | } | ||||||
|  | |||||||
| @ -78,6 +78,11 @@ public class WxCpServiceImpl implements WxCpService { | |||||||
|  |  | ||||||
|   protected WxSessionManager sessionManager = new StandardSessionManager(); |   protected WxSessionManager sessionManager = new StandardSessionManager(); | ||||||
|  |  | ||||||
|  |   /** | ||||||
|  |    * 临时文件目录 | ||||||
|  |    */ | ||||||
|  |   protected File tmpDirFile; | ||||||
|  |  | ||||||
|   public boolean checkSignature(String msgSignature, String timestamp, String nonce, String data) { |   public boolean checkSignature(String msgSignature, String timestamp, String nonce, String data) { | ||||||
|     try { |     try { | ||||||
|       return SHA1.gen(wxCpConfigStorage.getToken(), timestamp, nonce, data).equals(msgSignature); |       return SHA1.gen(wxCpConfigStorage.getToken(), timestamp, nonce, data).equals(msgSignature); | ||||||
| @ -236,7 +241,8 @@ public class WxCpServiceImpl implements WxCpService { | |||||||
|  |  | ||||||
|   public File mediaDownload(String media_id) throws WxErrorException { |   public File mediaDownload(String media_id) throws WxErrorException { | ||||||
|     String url = "https://qyapi.weixin.qq.com/cgi-bin/media/get"; |     String url = "https://qyapi.weixin.qq.com/cgi-bin/media/get"; | ||||||
|     return execute(new MediaDownloadRequestExecutor(), url, "media_id=" + media_id); |      | ||||||
|  |     return execute(new MediaDownloadRequestExecutor(wxCpConfigStorage.getTmpDirFile()), url, "media_id=" + media_id); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |  | ||||||
| @ -639,6 +645,14 @@ public class WxCpServiceImpl implements WxCpService { | |||||||
|     this.sessionManager = sessionManager; |     this.sessionManager = sessionManager; | ||||||
|   } |   } | ||||||
|    |    | ||||||
|  |   public File getTmpDirFile() { | ||||||
|  |     return tmpDirFile; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public void setTmpDirFile(File tmpDirFile) { | ||||||
|  |     this.tmpDirFile = tmpDirFile; | ||||||
|  |   } | ||||||
|  |  | ||||||
|   public static void main(String[] args) { |   public static void main(String[] args) { | ||||||
|     Float a = 3.1f; |     Float a = 3.1f; | ||||||
|     System.out.println(3.1d); |     System.out.println(3.1d); | ||||||
|  | |||||||
| @ -1,5 +1,7 @@ | |||||||
| package me.chanjar.weixin.mp.api; | package me.chanjar.weixin.mp.api; | ||||||
|  |  | ||||||
|  | import java.io.File; | ||||||
|  |  | ||||||
| import me.chanjar.weixin.common.bean.WxAccessToken; | import me.chanjar.weixin.common.bean.WxAccessToken; | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @ -68,7 +70,8 @@ public interface WxMpConfigStorage { | |||||||
|  |  | ||||||
|   public String getHttp_proxy_username(); |   public String getHttp_proxy_username(); | ||||||
|  |  | ||||||
|  |  | ||||||
|   public String getHttp_proxy_password(); |   public String getHttp_proxy_password(); | ||||||
|    |    | ||||||
|  |   public File getTmpDirFile(); | ||||||
|  |  | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,5 +1,7 @@ | |||||||
| package me.chanjar.weixin.mp.api; | package me.chanjar.weixin.mp.api; | ||||||
|  |  | ||||||
|  | import java.io.File; | ||||||
|  |  | ||||||
| import me.chanjar.weixin.common.bean.WxAccessToken; | import me.chanjar.weixin.common.bean.WxAccessToken; | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @ -28,6 +30,11 @@ public class WxMpInMemoryConfigStorage implements WxMpConfigStorage { | |||||||
|   protected volatile String jsapiTicket; |   protected volatile String jsapiTicket; | ||||||
|   protected volatile long jsapiTicketExpiresTime; |   protected volatile long jsapiTicketExpiresTime; | ||||||
|  |  | ||||||
|  |   /** | ||||||
|  |    * 临时文件目录 | ||||||
|  |    */ | ||||||
|  |   protected volatile File tmpDirFile; | ||||||
|  |    | ||||||
|   public String getAccessToken() { |   public String getAccessToken() { | ||||||
|     return this.accessToken; |     return this.accessToken; | ||||||
|   } |   } | ||||||
| @ -181,6 +188,7 @@ public class WxMpInMemoryConfigStorage implements WxMpConfigStorage { | |||||||
|         ", http_proxy_password='" + http_proxy_password + '\'' + |         ", http_proxy_password='" + http_proxy_password + '\'' + | ||||||
|         ", jsapiTicket='" + jsapiTicket + '\'' + |         ", jsapiTicket='" + jsapiTicket + '\'' + | ||||||
|         ", jsapiTicketExpiresTime='" + jsapiTicketExpiresTime + '\'' + |         ", jsapiTicketExpiresTime='" + jsapiTicketExpiresTime + '\'' + | ||||||
|  |         ", tmpDirFile='" + tmpDirFile + '\'' + | ||||||
|         '}'; |         '}'; | ||||||
|   } |   } | ||||||
|  |  | ||||||
| @ -201,4 +209,9 @@ public class WxMpInMemoryConfigStorage implements WxMpConfigStorage { | |||||||
|     public void setPartnerKey(String partnerKey) { |     public void setPartnerKey(String partnerKey) { | ||||||
|         this.partnerKey = partnerKey; |         this.partnerKey = partnerKey; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public File getTmpDirFile() { | ||||||
|  |       return this.getTmpDirFile(); | ||||||
|  |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -7,6 +7,7 @@ import com.google.gson.internal.Streams; | |||||||
| import com.google.gson.reflect.TypeToken; | import com.google.gson.reflect.TypeToken; | ||||||
| import com.google.gson.stream.JsonReader; | import com.google.gson.stream.JsonReader; | ||||||
| import com.thoughtworks.xstream.XStream; | import com.thoughtworks.xstream.XStream; | ||||||
|  |  | ||||||
| import me.chanjar.weixin.common.bean.WxAccessToken; | import me.chanjar.weixin.common.bean.WxAccessToken; | ||||||
| import me.chanjar.weixin.common.bean.WxMenu; | import me.chanjar.weixin.common.bean.WxMenu; | ||||||
| import me.chanjar.weixin.common.bean.WxJsapiSignature; | import me.chanjar.weixin.common.bean.WxJsapiSignature; | ||||||
| @ -27,6 +28,7 @@ import me.chanjar.weixin.mp.bean.*; | |||||||
| import me.chanjar.weixin.mp.bean.result.*; | import me.chanjar.weixin.mp.bean.result.*; | ||||||
| import me.chanjar.weixin.mp.util.http.QrCodeRequestExecutor; | import me.chanjar.weixin.mp.util.http.QrCodeRequestExecutor; | ||||||
| import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | ||||||
|  |  | ||||||
| import org.apache.http.Consts; | import org.apache.http.Consts; | ||||||
| import org.apache.http.HttpHost; | import org.apache.http.HttpHost; | ||||||
| import org.apache.http.auth.AuthScope; | import org.apache.http.auth.AuthScope; | ||||||
| @ -214,7 +216,7 @@ public class WxMpServiceImpl implements WxMpService { | |||||||
|    |    | ||||||
|   public File mediaDownload(String media_id) throws WxErrorException { |   public File mediaDownload(String media_id) throws WxErrorException { | ||||||
|     String url = "http://file.api.weixin.qq.com/cgi-bin/media/get"; |     String url = "http://file.api.weixin.qq.com/cgi-bin/media/get"; | ||||||
|     return execute(new MediaDownloadRequestExecutor(), url, "media_id=" + media_id); |     return execute(new MediaDownloadRequestExecutor(wxMpConfigStorage.getTmpDirFile()), url, "media_id=" + media_id); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   public WxMpMassUploadResult massNewsUpload(WxMpMassNews news) throws WxErrorException { |   public WxMpMassUploadResult massNewsUpload(WxMpMassNews news) throws WxErrorException { | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 ukid
					ukid