mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-08-24 07:23:01 +08:00
重构代码,将用户管理、分组管理以及二维码相关的接口分别移到单独类中管理
This commit is contained in:
parent
175bf9bbba
commit
fcbdc8686e
@ -0,0 +1,69 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.mp.bean.WxMpGroup;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户分组相关操作接口
|
||||
* @author Binary Wang
|
||||
*
|
||||
*/
|
||||
public interface WxMpGroupService {
|
||||
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 分组管理接口 - 创建分组
|
||||
* 最多支持创建500个分组
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口
|
||||
* </pre>
|
||||
*
|
||||
* @param name 分组名字(30个字符以内)
|
||||
*/
|
||||
public WxMpGroup groupCreate(String name) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 分组管理接口 - 查询所有分组
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口
|
||||
* </pre>
|
||||
*/
|
||||
public List<WxMpGroup> groupGet() throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 分组管理接口 - 查询用户所在分组
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口
|
||||
* </pre>
|
||||
*
|
||||
* @param openid 微信用户的openid
|
||||
*/
|
||||
public long userGetGroup(String openid) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 分组管理接口 - 修改分组名
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口
|
||||
*
|
||||
* 如果id为0(未分组),1(黑名单),2(星标组),或者不存在的id,微信会返回系统繁忙的错误
|
||||
* </pre>
|
||||
*
|
||||
* @param group 要更新的group,group的id,name必须设置
|
||||
*/
|
||||
public void groupUpdate(WxMpGroup group) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 分组管理接口 - 移动用户分组
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口
|
||||
*
|
||||
* 如果to_groupid为0(未分组),1(黑名单),2(星标组),或者不存在的id,微信会返回系统繁忙的错误
|
||||
* </pre>
|
||||
*
|
||||
* @param openid 用户openid
|
||||
* @param to_groupid 移动到的分组id
|
||||
*/
|
||||
public void userUpdateGroup(String openid, long to_groupid) throws WxErrorException;
|
||||
}
|
@ -1,23 +1,24 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Date;
|
||||
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfAccountRequest;
|
||||
import me.chanjar.weixin.mp.bean.kefu.result.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 客服接口 ,
|
||||
* 命名采用kefu拼音的原因是:
|
||||
* 其英文CustomerService如果再加上Service后缀显得有点啰嗦,
|
||||
* 如果不加又显得表意不完整
|
||||
* @author Binary Wang
|
||||
*
|
||||
* @author Binary Wang
|
||||
*/
|
||||
public interface WxMpKefuService {
|
||||
|
||||
//*******************客服管理接口***********************//
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 获取客服基本信息
|
||||
@ -83,6 +84,7 @@ public interface WxMpKefuService {
|
||||
boolean kfAccountDel(String kfAccount) throws WxErrorException;
|
||||
|
||||
//*******************客服会话控制接口***********************//
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 创建会话
|
||||
@ -134,6 +136,7 @@ public interface WxMpKefuService {
|
||||
WxMpKfSessionWaitCaseList kfSessionGetWaitCase() throws WxErrorException;
|
||||
|
||||
//*******************获取聊天记录的接口***********************//
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 获取聊天记录(原始接口)
|
||||
|
@ -19,10 +19,11 @@ public interface WxMpMaterialService {
|
||||
|
||||
/**
|
||||
* 新增临时素材
|
||||
* @see #mediaUpload(String, String, InputStream)
|
||||
*
|
||||
* @param mediaType
|
||||
* @param file
|
||||
* @throws WxErrorException
|
||||
* @see #mediaUpload(String, String, InputStream)
|
||||
*/
|
||||
public WxMediaUploadResult mediaUpload(String mediaType, File file) throws WxErrorException;
|
||||
|
||||
@ -33,6 +34,7 @@ public interface WxMpMaterialService {
|
||||
* 根据微信文档,视频文件下载不了,会返回null
|
||||
* 详情请见: <a href="http://mp.weixin.qq.com/wiki/9/677a85e3f3849af35de54bb5516c2521.html">获取临时素材</a>
|
||||
* </pre>
|
||||
*
|
||||
* @param media_id
|
||||
* @return 保存到本地的临时文件
|
||||
* @throws WxErrorException
|
||||
@ -44,6 +46,7 @@ public interface WxMpMaterialService {
|
||||
* 上传图文消息内的图片获取URL
|
||||
* 详情请见:http://mp.weixin.qq.com/wiki/15/40b6865b893947b764e2de8e4a1fb55f.html#.E4.B8.8A.E4.BC.A0.E5.9B.BE.E6.96.87.E6.B6.88.E6.81.AF.E5.86.85.E7.9A.84.E5.9B.BE.E7.89.87.E8.8E.B7.E5.8F.96URL.E3.80.90.E8.AE.A2.E9.98.85.E5.8F.B7.E4.B8.8E.E6.9C.8D.E5.8A.A1.E5.8F.B7.E8.AE.A4.E8.AF.81.E5.90.8E.E5.9D.87.E5.8F.AF.E7.94.A8.E3.80.91
|
||||
* </pre>
|
||||
*
|
||||
* @param file
|
||||
* @return WxMediaImgUploadResult 返回图片url
|
||||
* @throws WxErrorException
|
||||
@ -63,6 +66,7 @@ public interface WxMpMaterialService {
|
||||
*
|
||||
* 详情请见: <a href="http://mp.weixin.qq.com/wiki/15/2d353966323806a202cd2deaafe8e557.html">新增临时素材</a>
|
||||
* </pre>
|
||||
*
|
||||
* @param mediaType 媒体类型, 请看{@link me.chanjar.weixin.common.api.WxConsts}
|
||||
* @param fileType 文件类型,请看{@link me.chanjar.weixin.common.api.WxConsts}
|
||||
* @param inputStream 输入流
|
||||
@ -82,6 +86,7 @@ public interface WxMpMaterialService {
|
||||
*
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/14/7e6c03263063f4813141c3e17dd4350a.html
|
||||
* </pre>
|
||||
*
|
||||
* @param mediaType 媒体类型, 请看{@link me.chanjar.weixin.common.api.WxConsts}
|
||||
* @param material 上传的素材, 请看{@link me.chanjar.weixin.mp.bean.WxMpMaterial}
|
||||
*/
|
||||
@ -93,6 +98,7 @@ public interface WxMpMaterialService {
|
||||
*
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/14/7e6c03263063f4813141c3e17dd4350a.html
|
||||
* </pre>
|
||||
*
|
||||
* @param news 上传的图文消息, 请看{@link me.chanjar.weixin.mp.bean.WxMpMaterialNews}
|
||||
*/
|
||||
public WxMpMaterialUploadResult materialNewsUpload(WxMpMaterialNews news) throws WxErrorException;
|
||||
@ -103,6 +109,7 @@ public interface WxMpMaterialService {
|
||||
*
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/4/b3546879f07623cb30df9ca0e420a5d0.html
|
||||
* </pre>
|
||||
*
|
||||
* @param media_id 永久素材的id
|
||||
*/
|
||||
public InputStream materialImageOrVoiceDownload(String media_id) throws WxErrorException;
|
||||
@ -113,6 +120,7 @@ public interface WxMpMaterialService {
|
||||
*
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/4/b3546879f07623cb30df9ca0e420a5d0.html
|
||||
* </pre>
|
||||
*
|
||||
* @param media_id 永久素材的id
|
||||
*/
|
||||
public WxMpMaterialVideoInfoResult materialVideoInfo(String media_id) throws WxErrorException;
|
||||
@ -123,6 +131,7 @@ public interface WxMpMaterialService {
|
||||
*
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/4/b3546879f07623cb30df9ca0e420a5d0.html
|
||||
* </pre>
|
||||
*
|
||||
* @param media_id 永久素材的id
|
||||
*/
|
||||
public WxMpMaterialNews materialNewsInfo(String media_id) throws WxErrorException;
|
||||
@ -133,6 +142,7 @@ public interface WxMpMaterialService {
|
||||
*
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/4/19a59cba020d506e767360ca1be29450.html
|
||||
* </pre>
|
||||
*
|
||||
* @param wxMpMaterialArticleUpdate 用来更新图文素材的bean, 请看{@link me.chanjar.weixin.mp.bean.WxMpMaterialArticleUpdate}
|
||||
*/
|
||||
public boolean materialNewsUpdate(WxMpMaterialArticleUpdate wxMpMaterialArticleUpdate) throws WxErrorException;
|
||||
@ -143,6 +153,7 @@ public interface WxMpMaterialService {
|
||||
*
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/5/e66f61c303db51a6c0f90f46b15af5f5.html
|
||||
* </pre>
|
||||
*
|
||||
* @param media_id 永久素材的id
|
||||
*/
|
||||
public boolean materialDelete(String media_id) throws WxErrorException;
|
||||
@ -162,6 +173,7 @@ public interface WxMpMaterialService {
|
||||
*
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/12/2108cd7aafff7f388f41f37efa710204.html
|
||||
* </pre>
|
||||
*
|
||||
* @param offset 从全部素材的该偏移位置开始返回,0表示从第一个素材 返回
|
||||
* @param count 返回素材的数量,取值在1到20之间
|
||||
*/
|
||||
@ -173,6 +185,7 @@ public interface WxMpMaterialService {
|
||||
*
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/12/2108cd7aafff7f388f41f37efa710204.html
|
||||
* </pre>
|
||||
*
|
||||
* @param type 媒体类型, 请看{@link me.chanjar.weixin.common.api.WxConsts}
|
||||
* @param offset 从全部素材的该偏移位置开始返回,0表示从第一个素材 返回
|
||||
* @param count 返回素材的数量,取值在1到20之间
|
||||
|
@ -2,16 +2,11 @@ package me.chanjar.weixin.mp.api;
|
||||
|
||||
import me.chanjar.weixin.common.bean.WxMenu;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfAccountRequest;
|
||||
import me.chanjar.weixin.mp.bean.kefu.result.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 菜单相关操作接口
|
||||
* @author Binary Wang
|
||||
*
|
||||
* @author Binary Wang
|
||||
*/
|
||||
public interface WxMpMenuService {
|
||||
|
||||
@ -38,6 +33,7 @@ public interface WxMpMenuService {
|
||||
* 删除个性化菜单接口
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/0/c48ccd12b69ae023159b4bfaa7c39c20.html
|
||||
* </pre>
|
||||
*
|
||||
* @param menuid
|
||||
*/
|
||||
public void menuDelete(String menuid) throws WxErrorException;
|
||||
@ -55,6 +51,7 @@ public interface WxMpMenuService {
|
||||
* 测试个性化菜单匹配结果
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/0/c48ccd12b69ae023159b4bfaa7c39c20.html
|
||||
* </pre>
|
||||
*
|
||||
* @param userid 可以是粉丝的OpenID,也可以是粉丝的微信号。
|
||||
*/
|
||||
public WxMenu menuTryMatch(String userid) throws WxErrorException;
|
||||
|
@ -0,0 +1,77 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* 二维码相关操作接口
|
||||
*
|
||||
* @author Binary Wang
|
||||
*/
|
||||
public interface WxMpQrcodeService {
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 换取临时二维码ticket
|
||||
* 详情请见: <a href="http://mp.weixin.qq.com/wiki/18/167e7d94df85d8389df6c94a7a8f78ba.html">生成带参数的二维码</a>
|
||||
* </pre>
|
||||
*
|
||||
* @param scene_id 参数。
|
||||
* @param expire_seconds 过期秒数,默认60秒,最小60秒,最大1800秒
|
||||
*/
|
||||
public WxMpQrCodeTicket qrCodeCreateTmpTicket(int scene_id, Integer expire_seconds) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 换取永久二维码ticket
|
||||
* 详情请见: <a href="http://mp.weixin.qq.com/wiki/18/167e7d94df85d8389df6c94a7a8f78ba.html">生成带参数的二维码</a>
|
||||
* </pre>
|
||||
*
|
||||
* @param scene_id 参数。永久二维码时最大值为100000(目前参数只支持1--100000)
|
||||
*/
|
||||
public WxMpQrCodeTicket qrCodeCreateLastTicket(int scene_id) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 换取永久字符串二维码ticket
|
||||
* 详情请见: <a href="http://mp.weixin.qq.com/wiki/18/167e7d94df85d8389df6c94a7a8f78ba.html">生成带参数的二维码</a>
|
||||
* </pre>
|
||||
*
|
||||
* @param scene_str 参数。字符串类型长度现在为1到64
|
||||
*/
|
||||
public WxMpQrCodeTicket qrCodeCreateLastTicket(String scene_str) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 换取二维码图片文件,jpg格式
|
||||
* 详情请见: <a href="http://mp.weixin.qq.com/wiki/18/167e7d94df85d8389df6c94a7a8f78ba.html">生成带参数的二维码</a>
|
||||
* </pre>
|
||||
*
|
||||
* @param ticket 二维码ticket
|
||||
*/
|
||||
public File qrCodePicture(WxMpQrCodeTicket ticket) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 换取二维码图片url地址(可以选择是否生成压缩的网址)
|
||||
* 详情请见: <a href="http://mp.weixin.qq.com/wiki/18/167e7d94df85d8389df6c94a7a8f78ba.html">生成带参数的二维码</a>
|
||||
* </pre>
|
||||
*
|
||||
* @param ticket 二维码ticket
|
||||
* @param needShortUrl 是否需要压缩的二维码地址
|
||||
*/
|
||||
public String qrCodePictureUrl(String ticket, boolean needShortUrl) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 换取二维码图片url地址
|
||||
* 详情请见: <a href="http://mp.weixin.qq.com/wiki/18/167e7d94df85d8389df6c94a7a8f78ba.html">生成带参数的二维码</a>
|
||||
* </pre>
|
||||
*
|
||||
* @param ticket 二维码ticket
|
||||
*/
|
||||
public String qrCodePictureUrl(String ticket) throws WxErrorException;
|
||||
|
||||
}
|
@ -1,40 +1,14 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import me.chanjar.weixin.common.bean.WxCardApiSignature;
|
||||
import me.chanjar.weixin.common.bean.WxJsapiSignature;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.http.RequestExecutor;
|
||||
import me.chanjar.weixin.mp.bean.WxMpCustomMessage;
|
||||
import me.chanjar.weixin.mp.bean.WxMpGroup;
|
||||
import me.chanjar.weixin.mp.bean.WxMpIndustry;
|
||||
import me.chanjar.weixin.mp.bean.WxMpMassGroupMessage;
|
||||
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.WxMpMassVideo;
|
||||
import me.chanjar.weixin.mp.bean.WxMpSemanticQuery;
|
||||
import me.chanjar.weixin.mp.bean.WxMpTemplateMessage;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpCardResult;
|
||||
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.WxMpPayCallback;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpPayRefundResult;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpPayResult;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpPrepayIdResult;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpSemanticQueryResult;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUser;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUserCumulate;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUserList;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUserSummary;
|
||||
import me.chanjar.weixin.mp.bean.result.WxRedpackResult;
|
||||
import me.chanjar.weixin.mp.bean.*;
|
||||
import me.chanjar.weixin.mp.bean.result.*;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 微信API的Service
|
||||
@ -42,6 +16,7 @@ import me.chanjar.weixin.mp.bean.result.WxRedpackResult;
|
||||
public interface WxMpService {
|
||||
|
||||
public static final SimpleDateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 验证推送过来的消息的正确性
|
||||
@ -52,6 +27,7 @@ public interface WxMpService {
|
||||
|
||||
/**
|
||||
* 获取access_token, 不强制刷新access_token
|
||||
*
|
||||
* @see #getAccessToken(boolean)
|
||||
*/
|
||||
public String getAccessToken() throws WxErrorException;
|
||||
@ -64,15 +40,17 @@ public interface WxMpService {
|
||||
* 另:本service的所有方法都会在access_token过期是调用此方法
|
||||
*
|
||||
* 程序员在非必要情况下尽量不要主动调用此方法
|
||||
|
||||
*
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=获取access_token
|
||||
* </pre>
|
||||
*
|
||||
* @param forceRefresh 强制刷新
|
||||
*/
|
||||
public String getAccessToken(boolean forceRefresh) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 获得jsapi_ticket,不强制刷新jsapi_ticket
|
||||
*
|
||||
* @see #getJsapiTicket(boolean)
|
||||
*/
|
||||
public String getJsapiTicket() throws WxErrorException;
|
||||
@ -84,6 +62,7 @@ public interface WxMpService {
|
||||
*
|
||||
* 详情请见:http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html#.E9.99.84.E5.BD.951-JS-SDK.E4.BD.BF.E7.94.A8.E6.9D.83.E9.99.90.E7.AD.BE.E5.90.8D.E7.AE.97.E6.B3.95
|
||||
* </pre>
|
||||
*
|
||||
* @param forceRefresh 强制刷新
|
||||
*/
|
||||
public String getJsapiTicket(boolean forceRefresh) throws WxErrorException;
|
||||
@ -111,6 +90,7 @@ public interface WxMpService {
|
||||
*
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=高级群发接口
|
||||
* </pre>
|
||||
*
|
||||
* @param news
|
||||
* @throws WxErrorException
|
||||
* @see #massGroupMessageSend(me.chanjar.weixin.mp.bean.WxMpMassGroupMessage)
|
||||
@ -123,6 +103,7 @@ public interface WxMpService {
|
||||
* 上传群发用的视频,上传后才能群发视频消息
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=高级群发接口
|
||||
* </pre>
|
||||
*
|
||||
* @see #massGroupMessageSend(me.chanjar.weixin.mp.bean.WxMpMassGroupMessage)
|
||||
* @see #massOpenIdsMessageSend(me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage)
|
||||
*/
|
||||
@ -148,146 +129,12 @@ public interface WxMpService {
|
||||
*/
|
||||
public WxMpMassSendResult massOpenIdsMessageSend(WxMpMassOpenIdsMessage message) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 分组管理接口 - 创建分组
|
||||
* 最多支持创建500个分组
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口
|
||||
* </pre>
|
||||
* @param name 分组名字(30个字符以内)
|
||||
*/
|
||||
public WxMpGroup groupCreate(String name) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 分组管理接口 - 查询所有分组
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口
|
||||
* </pre>
|
||||
*/
|
||||
public List<WxMpGroup> groupGet() throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 分组管理接口 - 查询用户所在分组
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口
|
||||
* </pre>
|
||||
* @param openid 微信用户的openid
|
||||
*/
|
||||
public long userGetGroup(String openid) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 分组管理接口 - 修改分组名
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口
|
||||
*
|
||||
* 如果id为0(未分组),1(黑名单),2(星标组),或者不存在的id,微信会返回系统繁忙的错误
|
||||
* </pre>
|
||||
* @param group 要更新的group,group的id,name必须设置
|
||||
*/
|
||||
public void groupUpdate(WxMpGroup group) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 分组管理接口 - 移动用户分组
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口
|
||||
*
|
||||
* 如果to_groupid为0(未分组),1(黑名单),2(星标组),或者不存在的id,微信会返回系统繁忙的错误
|
||||
* </pre>
|
||||
* @param openid 用户openid
|
||||
* @param to_groupid 移动到的分组id
|
||||
*/
|
||||
public void userUpdateGroup(String openid, long to_groupid) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 设置用户备注名接口
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=设置用户备注名接口
|
||||
* </pre>
|
||||
* @param openid 用户openid
|
||||
* @param remark 备注名
|
||||
*/
|
||||
public void userUpdateRemark(String openid, String remark) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 获取用户基本信息
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=获取用户基本信息
|
||||
* </pre>
|
||||
* @param openid 用户openid
|
||||
* @param lang 语言,zh_CN 简体(默认),zh_TW 繁体,en 英语
|
||||
*/
|
||||
public WxMpUser userInfo(String openid, String lang) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 获取关注者列表
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=获取关注者列表
|
||||
* </pre>
|
||||
* @param next_openid 可选,第一个拉取的OPENID,null为从头开始拉取
|
||||
*/
|
||||
public WxMpUserList userList(String next_openid) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 换取临时二维码ticket
|
||||
* 详情请见: <a href="http://mp.weixin.qq.com/wiki/18/167e7d94df85d8389df6c94a7a8f78ba.html">生成带参数的二维码</a>
|
||||
* </pre>
|
||||
* @param scene_id 参数。
|
||||
* @param expire_seconds 过期秒数,默认60秒,最小60秒,最大1800秒
|
||||
*/
|
||||
public WxMpQrCodeTicket qrCodeCreateTmpTicket(int scene_id, Integer expire_seconds) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 换取永久二维码ticket
|
||||
* 详情请见: <a href="http://mp.weixin.qq.com/wiki/18/167e7d94df85d8389df6c94a7a8f78ba.html">生成带参数的二维码</a>
|
||||
* </pre>
|
||||
* @param scene_id 参数。永久二维码时最大值为100000(目前参数只支持1--100000)
|
||||
*/
|
||||
public WxMpQrCodeTicket qrCodeCreateLastTicket(int scene_id) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 换取永久字符串二维码ticket
|
||||
* 详情请见: <a href="http://mp.weixin.qq.com/wiki/18/167e7d94df85d8389df6c94a7a8f78ba.html">生成带参数的二维码</a>
|
||||
* </pre>
|
||||
*
|
||||
* @param scene_str 参数。字符串类型长度现在为1到64
|
||||
*/
|
||||
public WxMpQrCodeTicket qrCodeCreateLastTicket(String scene_str) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 换取二维码图片文件,jpg格式
|
||||
* 详情请见: <a href="http://mp.weixin.qq.com/wiki/18/167e7d94df85d8389df6c94a7a8f78ba.html">生成带参数的二维码</a>
|
||||
* </pre>
|
||||
* @param ticket 二维码ticket
|
||||
*/
|
||||
public File qrCodePicture(WxMpQrCodeTicket ticket) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 换取二维码图片url地址(可以选择是否生成压缩的网址)
|
||||
* 详情请见: <a href="http://mp.weixin.qq.com/wiki/18/167e7d94df85d8389df6c94a7a8f78ba.html">生成带参数的二维码</a>
|
||||
* </pre>
|
||||
* @param ticket 二维码ticket
|
||||
* @param needShortUrl 是否需要压缩的二维码地址
|
||||
*/
|
||||
public String qrCodePictureUrl(String ticket, boolean needShortUrl) throws WxErrorException;
|
||||
/**
|
||||
* <pre>
|
||||
* 换取二维码图片url地址
|
||||
* 详情请见: <a href="http://mp.weixin.qq.com/wiki/18/167e7d94df85d8389df6c94a7a8f78ba.html">生成带参数的二维码</a>
|
||||
* </pre>
|
||||
* @param ticket 二维码ticket
|
||||
*/
|
||||
public String qrCodePictureUrl(String ticket) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 长链接转短链接接口
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=长链接转短链接接口
|
||||
* </pre>
|
||||
*
|
||||
* @param long_url
|
||||
*/
|
||||
public String shortUrl(String long_url) throws WxErrorException;
|
||||
@ -297,9 +144,10 @@ public interface WxMpService {
|
||||
* 发送模板消息
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=模板消息接口
|
||||
* </pre>
|
||||
*
|
||||
* @param templateMessage
|
||||
* @throws WxErrorException
|
||||
* @return msgid
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
public String templateSend(WxMpTemplateMessage templateMessage) throws WxErrorException;
|
||||
|
||||
@ -316,6 +164,7 @@ public interface WxMpService {
|
||||
* 构造oauth2授权的url连接
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=网页授权获取用户基本信息
|
||||
* </pre>
|
||||
*
|
||||
* @param scope
|
||||
* @param state
|
||||
* @return url
|
||||
@ -327,8 +176,8 @@ public interface WxMpService {
|
||||
* 构造oauth2授权的url连接
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=网页授权获取用户基本信息
|
||||
* </pre>
|
||||
* @param redirectURI
|
||||
* 用户授权完成后的重定向链接,无需urlencode, 方法内会进行encode
|
||||
*
|
||||
* @param redirectURI 用户授权完成后的重定向链接,无需urlencode, 方法内会进行encode
|
||||
* @param scope
|
||||
* @param state
|
||||
* @return url
|
||||
@ -354,6 +203,7 @@ public interface WxMpService {
|
||||
* <pre>
|
||||
* 用oauth2获取用户信息, 当前面引导授权时的scope是snsapi_userinfo的时候才可以
|
||||
* </pre>
|
||||
*
|
||||
* @param oAuth2AccessToken
|
||||
* @param lang zh_CN, zh_TW, en
|
||||
*/
|
||||
@ -363,6 +213,7 @@ public interface WxMpService {
|
||||
* <pre>
|
||||
* 验证oauth2的access token是否有效
|
||||
* </pre>
|
||||
*
|
||||
* @param oAuth2AccessToken
|
||||
*/
|
||||
public boolean oauth2validateAccessToken(WxMpOAuth2AccessToken oAuth2AccessToken);
|
||||
@ -375,26 +226,6 @@ public interface WxMpService {
|
||||
*/
|
||||
String[] getCallbackIP() throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 获取用户增减数据
|
||||
* http://mp.weixin.qq.com/wiki/3/ecfed6e1a0a03b5f35e5efac98e864b7.html
|
||||
* </pre>
|
||||
* @param beginDate 最大时间跨度7天
|
||||
* @param endDate endDate不能早于begingDate
|
||||
*/
|
||||
List<WxMpUserSummary> getUserSummary(Date beginDate, Date endDate) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 获取累计用户数据
|
||||
* http://mp.weixin.qq.com/wiki/3/ecfed6e1a0a03b5f35e5efac98e864b7.html
|
||||
* </pre>
|
||||
* @param beginDate 最大时间跨度7天
|
||||
* @param endDate endDate不能早于begingDate
|
||||
*/
|
||||
List<WxMpUserCumulate> getUserCumulate(Date beginDate, Date endDate) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 当本Service没有实现某个API的时候,可以用这个,针对所有微信API中的GET请求
|
||||
*/
|
||||
@ -438,6 +269,7 @@ public interface WxMpService {
|
||||
/**
|
||||
* 统一下单(详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1)
|
||||
* 在发起微信支付前,需要调用统一下单接口,获取"预支付交易会话标识"
|
||||
*
|
||||
* @param openId 支付人openId
|
||||
* @param outTradeNo 商户端对应订单号
|
||||
* @param amt 金额(单位元)
|
||||
@ -454,8 +286,7 @@ public interface WxMpService {
|
||||
* 统一下单(详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1)
|
||||
* 在发起微信支付前,需要调用统一下单接口,获取"预支付交易会话标识"
|
||||
*
|
||||
* @param parameters
|
||||
* All required/optional parameters for weixin payment
|
||||
* @param parameters All required/optional parameters for weixin payment
|
||||
* @throws IllegalArgumentException
|
||||
*/
|
||||
WxMpPrepayIdResult getPrepayId(Map<String, String> parameters);
|
||||
@ -463,8 +294,8 @@ public interface WxMpService {
|
||||
/**
|
||||
* 该接口调用“统一下单”接口,并拼装发起支付请求需要的参数
|
||||
* 详见http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html#.E5.8F.91.E8.B5.B7.E4.B8.80.E4.B8.AA.E5.BE.AE.E4.BF.A1.E6.94.AF.E4.BB.98.E8.AF.B7.E6.B1.82
|
||||
* @param parameters
|
||||
* the required or optional parameters
|
||||
*
|
||||
* @param parameters the required or optional parameters
|
||||
*/
|
||||
Map<String, String> getPayInfo(Map<String, String> parameters) throws WxErrorException;
|
||||
|
||||
@ -472,6 +303,7 @@ public interface WxMpService {
|
||||
* 该接口调用“统一下单”接口,并拼装NATIVE发起支付请求需要的参数
|
||||
* 详见http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html#.E5.8F.91.E8.B5.B7.E4.B8.80.E4.B8.AA.E5.BE.AE.E4.BF.A1.E6.94.AF.E4.BB.98.E8.AF.B7.E6.B1.82
|
||||
* tradeType 交易类型 NATIVE (其他交易类型JSAPI,APP,WAP)
|
||||
*
|
||||
* @param productId 商户商品ID
|
||||
* @param outTradeNo 商户端对应订单号
|
||||
* @param amt 金额(单位元)
|
||||
@ -487,6 +319,7 @@ public interface WxMpService {
|
||||
* 该接口调用“统一下单”接口,并拼装JSAPI发起支付请求需要的参数
|
||||
* 详见http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html#.E5.8F.91.E8.B5.B7.E4.B8.80.E4.B8.AA.E5.BE.AE.E4.BF.A1.E6.94.AF.E4.BB.98.E8.AF.B7.E6.B1.82
|
||||
* tradeType 交易类型 JSAPI(其他交易类型NATIVE,APP,WAP)
|
||||
*
|
||||
* @param openId 支付人openId
|
||||
* @param outTradeNo 商户端对应订单号
|
||||
* @param amt 金额(单位元)
|
||||
@ -501,6 +334,7 @@ public interface WxMpService {
|
||||
/**
|
||||
* 该接口提供所有微信支付订单的查询,当支付通知处理异常戒丢失的情冴,商户可以通过该接口查询订单支付状态。
|
||||
* 详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_2
|
||||
*
|
||||
* @param transactionId
|
||||
* @param outTradeNo
|
||||
*/
|
||||
@ -509,6 +343,7 @@ public interface WxMpService {
|
||||
/**
|
||||
* 读取支付结果通知
|
||||
* 详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_7
|
||||
*
|
||||
* @param xmlData
|
||||
*/
|
||||
WxMpPayCallback getJSSDKCallbackData(String xmlData);
|
||||
@ -516,6 +351,7 @@ public interface WxMpService {
|
||||
/**
|
||||
* 微信支付-申请退款
|
||||
* 详见 https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_4
|
||||
*
|
||||
* @param parameters 需要传入的退款参数的Map。以下几项为参数的必须项:<br/>
|
||||
* <li/> transaction_id
|
||||
* <li/> out_trade_no (仅在上述transaction_id为空时是必须项)
|
||||
@ -532,6 +368,7 @@ public interface WxMpService {
|
||||
* 计算Map键值对是否和签名相符,
|
||||
* 按照字段名的 ASCII 码从小到大排序(字典序)后,使用 URL 键值对的 格式(即 key1=value1&key2=value2...)拼接成字符串
|
||||
* </pre>
|
||||
*
|
||||
* @param kvm
|
||||
* @param signature
|
||||
*/
|
||||
@ -539,7 +376,7 @@ public interface WxMpService {
|
||||
|
||||
/**
|
||||
* 发送微信红包给个人用户
|
||||
*
|
||||
* <p>
|
||||
* 需要传入的必填参数如下:
|
||||
* mch_billno//商户订单号
|
||||
* send_name//商户名称
|
||||
@ -551,7 +388,7 @@ public interface WxMpService {
|
||||
* act_name//活动名称
|
||||
* remark //备注
|
||||
* 文档详见:https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_5
|
||||
*
|
||||
* <p>
|
||||
* 使用现金红包功能需要在xml配置文件中额外设置:
|
||||
* <partnerId></partnerId>微信商户平台ID
|
||||
* <partnerKey></partnerKey>商户平台设置的API密钥
|
||||
@ -562,9 +399,10 @@ public interface WxMpService {
|
||||
|
||||
/**
|
||||
* 获得卡券api_ticket,不强制刷新卡券api_ticket
|
||||
* @see #getCardApiTicket(boolean)
|
||||
*
|
||||
* @return 卡券api_ticket
|
||||
* @throws WxErrorException
|
||||
* @see #getCardApiTicket(boolean)
|
||||
*/
|
||||
public String getCardApiTicket() throws WxErrorException;
|
||||
|
||||
@ -575,6 +413,7 @@ public interface WxMpService {
|
||||
*
|
||||
* 详情请见:http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html#.E9.99.84.E5.BD.954-.E5.8D.A1.E5.88.B8.E6.89.A9.E5.B1.95.E5.AD.97.E6.AE.B5.E5.8F.8A.E7.AD.BE.E5.90.8D.E7.94.9F.E6.88.90.E7.AE.97.E6.B3.95
|
||||
* </pre>
|
||||
*
|
||||
* @param forceRefresh 强制刷新
|
||||
* @return 卡券api_ticket
|
||||
* @throws WxErrorException
|
||||
@ -600,6 +439,7 @@ public interface WxMpService {
|
||||
|
||||
/**
|
||||
* 卡券Code解码
|
||||
*
|
||||
* @param encryptCode 加密Code,通过JSSDK的chooseCard接口获得
|
||||
* @return 解密后的Code
|
||||
* @throws WxErrorException
|
||||
@ -608,6 +448,7 @@ public interface WxMpService {
|
||||
|
||||
/**
|
||||
* 卡券Code查询
|
||||
*
|
||||
* @param cardId 卡券ID代表一类卡券
|
||||
* @param code 单张卡券的唯一标准
|
||||
* @param checkConsume 是否校验code核销状态,填入true和false时的code异常状态返回数据不同
|
||||
@ -642,6 +483,7 @@ public interface WxMpService {
|
||||
* 卡券Mark接口。
|
||||
* 开发者在帮助消费者核销卡券之前,必须帮助先将此code(卡券串码)与一个openid绑定(即mark住),
|
||||
* 才能进一步调用核销接口,否则报错。
|
||||
*
|
||||
* @param code 卡券的code码
|
||||
* @param cardId 卡券的ID
|
||||
* @param openId 用券用户的openid
|
||||
@ -654,6 +496,7 @@ public interface WxMpService {
|
||||
/**
|
||||
* 查看卡券详情接口
|
||||
* 详见 https://mp.weixin.qq.com/wiki/14/8dd77aeaee85f922db5f8aa6386d385e.html#.E6.9F.A5.E7.9C.8B.E5.8D.A1.E5.88.B8.E8.AF.A6.E6.83.85
|
||||
*
|
||||
* @param cardId 卡券的ID
|
||||
* @return 返回的卡券详情JSON字符串
|
||||
* <br> [注] 由于返回的JSON格式过于复杂,难以定义其对应格式的Bean并且难以维护,因此只返回String格式的JSON串。
|
||||
@ -667,6 +510,7 @@ public interface WxMpService {
|
||||
* 预览接口
|
||||
* 详情请见:http://mp.weixin.qq.com/wiki/15/40b6865b893947b764e2de8e4a1fb55f.html#.E9.A2.84.E8.A7.88.E6.8E.A5.E5.8F.A3.E3.80.90.E8.AE.A2.E9.98.85.E5.8F.B7.E4.B8.8E.E6.9C.8D.E5.8A.A1.E5.8F.B7.E8.AE.A4.E8.AF.81.E5.90.8E.E5.9D.87.E5.8F.AF.E7.94.A8.E3.80.91
|
||||
* </pre>
|
||||
*
|
||||
* @param wxMpMassPreviewMessage
|
||||
* @return wxMpMassSendResult
|
||||
* @throws WxErrorException
|
||||
@ -679,6 +523,7 @@ public interface WxMpService {
|
||||
* 官方文档中暂未告知响应内容
|
||||
* 详情请见:http://mp.weixin.qq.com/wiki/5/6dde9eaa909f83354e0094dc3ad99e05.html#.E8.AE.BE.E7.BD.AE.E6.89.80.E5.B1.9E.E8.A1.8C.E4.B8.9A
|
||||
* </pre>
|
||||
*
|
||||
* @param wxMpIndustry
|
||||
* @return JsonObject
|
||||
* @throws WxErrorException
|
||||
@ -696,27 +541,52 @@ public interface WxMpService {
|
||||
*/
|
||||
WxMpIndustry getIndustry() throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 获取WxMpConfigStorage 对象
|
||||
*
|
||||
* @return WxMpConfigStorage
|
||||
*/
|
||||
WxMpConfigStorage getWxMpConfigStorage();
|
||||
|
||||
/**
|
||||
* 返回客服接口方法实现类,以方便调用个其各种接口
|
||||
*
|
||||
* @return WxMpKefuService
|
||||
*/
|
||||
WxMpKefuService getKefuService();
|
||||
|
||||
/**
|
||||
* 返回素材相关接口的方法实现类,以方便调用个其各种接口
|
||||
*
|
||||
* @return WxMpMaterialService
|
||||
*/
|
||||
WxMpMaterialService getMaterialService();
|
||||
|
||||
/**
|
||||
* 返回素材相关接口的方法实现类,以方便调用个其各种接口
|
||||
* 返回菜单相关接口的方法实现类,以方便调用个其各种接口
|
||||
*
|
||||
* @return WxMpMenuService
|
||||
*/
|
||||
WxMpMenuService getMenuService();
|
||||
|
||||
/**
|
||||
* 获取WxMpConfigStorage 对象
|
||||
* @return WxMpConfigStorage
|
||||
* 返回用户相关接口的方法实现类,以方便调用个其各种接口
|
||||
*
|
||||
* @return WxMpUserService
|
||||
*/
|
||||
WxMpConfigStorage getWxMpConfigStorage();
|
||||
WxMpUserService getUserService();
|
||||
|
||||
/**
|
||||
* 返回用户分组相关接口的方法实现类,以方便调用个其各种接口
|
||||
*
|
||||
* @return WxMpGroupService
|
||||
*/
|
||||
WxMpGroupService getGroupService();
|
||||
|
||||
/**
|
||||
* 返回二维码相关接口的方法实现类,以方便调用个其各种接口
|
||||
*
|
||||
* @return WxMpQrcodeService
|
||||
*/
|
||||
WxMpQrcodeService getQrcodeService();
|
||||
}
|
||||
|
@ -1,21 +1,26 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.SortedMap;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import com.google.gson.*;
|
||||
import com.google.gson.internal.Streams;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
import me.chanjar.weixin.common.bean.WxAccessToken;
|
||||
import me.chanjar.weixin.common.bean.WxCardApiSignature;
|
||||
import me.chanjar.weixin.common.bean.WxJsapiSignature;
|
||||
import me.chanjar.weixin.common.bean.result.WxError;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.session.StandardSessionManager;
|
||||
import me.chanjar.weixin.common.session.WxSessionManager;
|
||||
import me.chanjar.weixin.common.util.RandomUtils;
|
||||
import me.chanjar.weixin.common.util.crypto.SHA1;
|
||||
import me.chanjar.weixin.common.util.crypto.WxCryptUtil;
|
||||
import me.chanjar.weixin.common.util.http.*;
|
||||
import me.chanjar.weixin.common.util.xml.XStreamInitializer;
|
||||
import me.chanjar.weixin.mp.api.impl.*;
|
||||
import me.chanjar.weixin.mp.bean.*;
|
||||
import me.chanjar.weixin.mp.bean.result.*;
|
||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
import org.apache.http.Consts;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
@ -31,65 +36,11 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.slf4j.helpers.MessageFormatter;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.internal.Streams;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
|
||||
import me.chanjar.weixin.common.bean.WxAccessToken;
|
||||
import me.chanjar.weixin.common.bean.WxCardApiSignature;
|
||||
import me.chanjar.weixin.common.bean.WxJsapiSignature;
|
||||
import me.chanjar.weixin.common.bean.result.WxError;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.session.StandardSessionManager;
|
||||
import me.chanjar.weixin.common.session.WxSessionManager;
|
||||
import me.chanjar.weixin.common.util.RandomUtils;
|
||||
import me.chanjar.weixin.common.util.crypto.SHA1;
|
||||
import me.chanjar.weixin.common.util.crypto.WxCryptUtil;
|
||||
import me.chanjar.weixin.common.util.http.ApacheHttpClientBuilder;
|
||||
import me.chanjar.weixin.common.util.http.DefaultApacheHttpHttpClientBuilder;
|
||||
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.common.util.http.Utf8ResponseHandler;
|
||||
import me.chanjar.weixin.common.util.json.GsonHelper;
|
||||
import me.chanjar.weixin.common.util.xml.XStreamInitializer;
|
||||
import me.chanjar.weixin.mp.api.impl.WxMpKefuServiceImpl;
|
||||
import me.chanjar.weixin.mp.api.impl.WxMpMaterialServiceImpl;
|
||||
import me.chanjar.weixin.mp.api.impl.WxMpMenuServiceImpl;
|
||||
import me.chanjar.weixin.mp.bean.WxMpCustomMessage;
|
||||
import me.chanjar.weixin.mp.bean.WxMpGroup;
|
||||
import me.chanjar.weixin.mp.bean.WxMpIndustry;
|
||||
import me.chanjar.weixin.mp.bean.WxMpMassGroupMessage;
|
||||
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.WxMpMassVideo;
|
||||
import me.chanjar.weixin.mp.bean.WxMpSemanticQuery;
|
||||
import me.chanjar.weixin.mp.bean.WxMpTemplateMessage;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpCardResult;
|
||||
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.WxMpPayCallback;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpPayRefundResult;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpPayResult;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpPrepayIdResult;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpSemanticQueryResult;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUser;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUserCumulate;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUserList;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUserSummary;
|
||||
import me.chanjar.weixin.mp.bean.result.WxRedpackResult;
|
||||
import me.chanjar.weixin.mp.util.http.QrCodeRequestExecutor;
|
||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class WxMpServiceImpl implements WxMpService {
|
||||
|
||||
@ -118,6 +69,12 @@ public class WxMpServiceImpl implements WxMpService {
|
||||
|
||||
protected WxMpMenuService menuService = new WxMpMenuServiceImpl(this);
|
||||
|
||||
protected WxMpUserService userService = new WxMpUserServiceImpl(this);
|
||||
|
||||
protected WxMpGroupService groupService = new WxMpGroupServiceImpl(this);
|
||||
|
||||
protected WxMpQrcodeService qrCodeService = new WxMpQrcodeServiceImpl(this);
|
||||
|
||||
protected CloseableHttpClient httpClient;
|
||||
|
||||
protected HttpHost httpProxy;
|
||||
@ -266,158 +223,6 @@ public class WxMpServiceImpl implements WxMpService {
|
||||
return WxMpMassSendResult.fromJson(responseContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpGroup groupCreate(String name) throws WxErrorException {
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/groups/create";
|
||||
JsonObject json = new JsonObject();
|
||||
JsonObject groupJson = new JsonObject();
|
||||
json.add("group", groupJson);
|
||||
groupJson.addProperty("name", name);
|
||||
|
||||
String responseContent = execute(
|
||||
new SimplePostRequestExecutor(),
|
||||
url,
|
||||
json.toString());
|
||||
return WxMpGroup.fromJson(responseContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WxMpGroup> groupGet() throws WxErrorException {
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/groups/get";
|
||||
String responseContent = execute(new SimpleGetRequestExecutor(), url, null);
|
||||
/*
|
||||
* 操蛋的微信API,创建时返回的是 { group : { id : ..., name : ...} }
|
||||
* 查询时返回的是 { groups : [ { id : ..., name : ..., count : ... }, ... ] }
|
||||
*/
|
||||
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
|
||||
return WxMpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement.getAsJsonObject().get("groups"),
|
||||
new TypeToken<List<WxMpGroup>>() {
|
||||
}.getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public long userGetGroup(String openid) throws WxErrorException {
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/groups/getid";
|
||||
JsonObject o = new JsonObject();
|
||||
o.addProperty("openid", openid);
|
||||
String responseContent = execute(new SimplePostRequestExecutor(), url, o.toString());
|
||||
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
|
||||
return GsonHelper.getAsLong(tmpJsonElement.getAsJsonObject().get("groupid"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void groupUpdate(WxMpGroup group) throws WxErrorException {
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/groups/update";
|
||||
execute(new SimplePostRequestExecutor(), url, group.toJson());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void userUpdateGroup(String openid, long to_groupid) throws WxErrorException {
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/groups/members/update";
|
||||
JsonObject json = new JsonObject();
|
||||
json.addProperty("openid", openid);
|
||||
json.addProperty("to_groupid", to_groupid);
|
||||
execute(new SimplePostRequestExecutor(), url, json.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void userUpdateRemark(String openid, String remark) throws WxErrorException {
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/user/info/updateremark";
|
||||
JsonObject json = new JsonObject();
|
||||
json.addProperty("openid", openid);
|
||||
json.addProperty("remark", remark);
|
||||
execute(new SimplePostRequestExecutor(), url, json.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpUser userInfo(String openid, String lang) throws WxErrorException {
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/user/info";
|
||||
lang = lang == null ? "zh_CN" : lang;
|
||||
String responseContent = execute(new SimpleGetRequestExecutor(), url, "openid=" + openid + "&lang=" + lang);
|
||||
return WxMpUser.fromJson(responseContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpUserList userList(String next_openid) throws WxErrorException {
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/user/get";
|
||||
String responseContent = execute(new SimpleGetRequestExecutor(), url, next_openid == null ? null : "next_openid=" + next_openid);
|
||||
return WxMpUserList.fromJson(responseContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpQrCodeTicket qrCodeCreateTmpTicket(int scene_id, Integer expire_seconds) throws WxErrorException {
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/qrcode/create";
|
||||
JsonObject json = new JsonObject();
|
||||
json.addProperty("action_name", "QR_SCENE");
|
||||
if (expire_seconds != null) {
|
||||
json.addProperty("expire_seconds", expire_seconds);
|
||||
}
|
||||
JsonObject actionInfo = new JsonObject();
|
||||
JsonObject scene = new JsonObject();
|
||||
scene.addProperty("scene_id", scene_id);
|
||||
actionInfo.add("scene", scene);
|
||||
json.add("action_info", actionInfo);
|
||||
String responseContent = execute(new SimplePostRequestExecutor(), url, json.toString());
|
||||
return WxMpQrCodeTicket.fromJson(responseContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpQrCodeTicket qrCodeCreateLastTicket(int scene_id) throws WxErrorException {
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/qrcode/create";
|
||||
JsonObject json = new JsonObject();
|
||||
json.addProperty("action_name", "QR_LIMIT_SCENE");
|
||||
JsonObject actionInfo = new JsonObject();
|
||||
JsonObject scene = new JsonObject();
|
||||
scene.addProperty("scene_id", scene_id);
|
||||
actionInfo.add("scene", scene);
|
||||
json.add("action_info", actionInfo);
|
||||
String responseContent = execute(new SimplePostRequestExecutor(), url, json.toString());
|
||||
return WxMpQrCodeTicket.fromJson(responseContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpQrCodeTicket qrCodeCreateLastTicket(String scene_str) throws WxErrorException {
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/qrcode/create";
|
||||
JsonObject json = new JsonObject();
|
||||
json.addProperty("action_name", "QR_LIMIT_STR_SCENE");
|
||||
JsonObject actionInfo = new JsonObject();
|
||||
JsonObject scene = new JsonObject();
|
||||
scene.addProperty("scene_str", scene_str);
|
||||
actionInfo.add("scene", scene);
|
||||
json.add("action_info", actionInfo);
|
||||
String responseContent = execute(new SimplePostRequestExecutor(), url, json.toString());
|
||||
return WxMpQrCodeTicket.fromJson(responseContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public File qrCodePicture(WxMpQrCodeTicket ticket) throws WxErrorException {
|
||||
String url = "https://mp.weixin.qq.com/cgi-bin/showqrcode";
|
||||
return execute(new QrCodeRequestExecutor(), url, ticket);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String qrCodePictureUrl(String ticket, boolean needShortUrl) throws WxErrorException {
|
||||
String url = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=%s";
|
||||
try {
|
||||
String resultUrl = String.format(url,
|
||||
URLEncoder.encode(ticket, StandardCharsets.UTF_8.name()));
|
||||
if(needShortUrl){
|
||||
return this.shortUrl(resultUrl);
|
||||
}
|
||||
|
||||
return resultUrl;
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
WxError error = WxError.newBuilder().setErrorCode(-1)
|
||||
.setErrorMsg(e.getMessage()).build();
|
||||
throw new WxErrorException(error);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String qrCodePictureUrl(String ticket) throws WxErrorException {
|
||||
return qrCodePictureUrl(ticket, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String shortUrl(String long_url) throws WxErrorException {
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/shorturl";
|
||||
@ -562,33 +367,6 @@ public class WxMpServiceImpl implements WxMpService {
|
||||
return ipArray;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<WxMpUserSummary> getUserSummary(Date beginDate, Date endDate) throws WxErrorException {
|
||||
String url = "https://api.weixin.qq.com/datacube/getusersummary";
|
||||
JsonObject param = new JsonObject();
|
||||
param.addProperty("begin_date", SIMPLE_DATE_FORMAT.format(beginDate));
|
||||
param.addProperty("end_date", SIMPLE_DATE_FORMAT.format(endDate));
|
||||
String responseContent = post(url, param.toString());
|
||||
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
|
||||
return WxMpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement.getAsJsonObject().get("list"),
|
||||
new TypeToken<List<WxMpUserSummary>>() {
|
||||
}.getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WxMpUserCumulate> getUserCumulate(Date beginDate, Date endDate) throws WxErrorException {
|
||||
String url = "https://api.weixin.qq.com/datacube/getusercumulate";
|
||||
JsonObject param = new JsonObject();
|
||||
param.addProperty("begin_date", SIMPLE_DATE_FORMAT.format(beginDate));
|
||||
param.addProperty("end_date", SIMPLE_DATE_FORMAT.format(endDate));
|
||||
String responseContent = post(url, param.toString());
|
||||
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
|
||||
return WxMpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement.getAsJsonObject().get("list"),
|
||||
new TypeToken<List<WxMpUserCumulate>>() {
|
||||
}.getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get(String url, String queryParam) throws WxErrorException {
|
||||
return execute(new SimpleGetRequestExecutor(), url, queryParam);
|
||||
@ -1255,4 +1033,19 @@ public class WxMpServiceImpl implements WxMpService {
|
||||
return this.menuService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpUserService getUserService() {
|
||||
return this.userService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpGroupService getGroupService() {
|
||||
return this.groupService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpQrcodeService getQrcodeService() {
|
||||
return this.qrCodeService;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,72 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUser;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUserCumulate;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUserList;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUserSummary;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户管理和统计相关操作接口
|
||||
*
|
||||
* @author Binary Wang
|
||||
*/
|
||||
public interface WxMpUserService {
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 设置用户备注名接口
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=设置用户备注名接口
|
||||
* </pre>
|
||||
*
|
||||
* @param openid 用户openid
|
||||
* @param remark 备注名
|
||||
*/
|
||||
public void userUpdateRemark(String openid, String remark) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 获取用户基本信息
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=获取用户基本信息
|
||||
* </pre>
|
||||
*
|
||||
* @param openid 用户openid
|
||||
* @param lang 语言,zh_CN 简体(默认),zh_TW 繁体,en 英语
|
||||
*/
|
||||
public WxMpUser userInfo(String openid, String lang) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 获取关注者列表
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=获取关注者列表
|
||||
* </pre>
|
||||
*
|
||||
* @param next_openid 可选,第一个拉取的OPENID,null为从头开始拉取
|
||||
*/
|
||||
public WxMpUserList userList(String next_openid) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 获取用户增减数据
|
||||
* http://mp.weixin.qq.com/wiki/3/ecfed6e1a0a03b5f35e5efac98e864b7.html
|
||||
* </pre>
|
||||
*
|
||||
* @param beginDate 最大时间跨度7天
|
||||
* @param endDate endDate不能早于begingDate
|
||||
*/
|
||||
List<WxMpUserSummary> dataCubeUserSummary(Date beginDate, Date endDate) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 获取累计用户数据
|
||||
* http://mp.weixin.qq.com/wiki/3/ecfed6e1a0a03b5f35e5efac98e864b7.html
|
||||
* </pre>
|
||||
*
|
||||
* @param beginDate 最大时间跨度7天
|
||||
* @param endDate endDate不能早于begingDate
|
||||
*/
|
||||
List<WxMpUserCumulate> dataCubeUserCumulate(Date beginDate, Date endDate) throws WxErrorException;
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.internal.Streams;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
|
||||
import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
|
||||
import me.chanjar.weixin.common.util.json.GsonHelper;
|
||||
import me.chanjar.weixin.mp.api.WxMpGroupService;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.bean.WxMpGroup;
|
||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Binary Wang on 2016/7/21.
|
||||
*/
|
||||
public class WxMpGroupServiceImpl implements WxMpGroupService {
|
||||
private static final String API_URL_PREFIX = "https://api.weixin.qq.com/cgi-bin/groups";
|
||||
private WxMpService wxMpService;
|
||||
|
||||
public WxMpGroupServiceImpl(WxMpService wxMpService) {
|
||||
this.wxMpService = wxMpService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpGroup groupCreate(String name) throws WxErrorException {
|
||||
String url = API_URL_PREFIX + "/create";
|
||||
JsonObject json = new JsonObject();
|
||||
JsonObject groupJson = new JsonObject();
|
||||
json.add("group", groupJson);
|
||||
groupJson.addProperty("name", name);
|
||||
|
||||
String responseContent = this.wxMpService.execute(
|
||||
new SimplePostRequestExecutor(),
|
||||
url,
|
||||
json.toString());
|
||||
return WxMpGroup.fromJson(responseContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WxMpGroup> groupGet() throws WxErrorException {
|
||||
String url = API_URL_PREFIX + "/get";
|
||||
String responseContent = this.wxMpService.execute(new SimpleGetRequestExecutor(), url, null);
|
||||
/*
|
||||
* 操蛋的微信API,创建时返回的是 { group : { id : ..., name : ...} }
|
||||
* 查询时返回的是 { groups : [ { id : ..., name : ..., count : ... }, ... ] }
|
||||
*/
|
||||
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
|
||||
return WxMpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement.getAsJsonObject().get("groups"),
|
||||
new TypeToken<List<WxMpGroup>>() {
|
||||
}.getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public long userGetGroup(String openid) throws WxErrorException {
|
||||
String url = API_URL_PREFIX + "/getid";
|
||||
JsonObject o = new JsonObject();
|
||||
o.addProperty("openid", openid);
|
||||
String responseContent = this.wxMpService.execute(new SimplePostRequestExecutor(), url, o.toString());
|
||||
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
|
||||
return GsonHelper.getAsLong(tmpJsonElement.getAsJsonObject().get("groupid"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void groupUpdate(WxMpGroup group) throws WxErrorException {
|
||||
String url = API_URL_PREFIX + "/update";
|
||||
this.wxMpService.execute(new SimplePostRequestExecutor(), url, group.toJson());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void userUpdateGroup(String openid, long to_groupid) throws WxErrorException {
|
||||
String url = API_URL_PREFIX + "/members/update";
|
||||
JsonObject json = new JsonObject();
|
||||
json.addProperty("openid", openid);
|
||||
json.addProperty("to_groupid", to_groupid);
|
||||
this.wxMpService.execute(new SimplePostRequestExecutor(), url, json.toString());
|
||||
}
|
||||
|
||||
}
|
@ -7,11 +7,12 @@ import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.fs.FileUtils;
|
||||
import me.chanjar.weixin.common.util.http.MediaDownloadRequestExecutor;
|
||||
import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
|
||||
import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
|
||||
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
|
||||
import me.chanjar.weixin.mp.api.WxMpMaterialService;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.bean.*;
|
||||
import me.chanjar.weixin.mp.bean.WxMpMaterial;
|
||||
import me.chanjar.weixin.mp.bean.WxMpMaterialArticleUpdate;
|
||||
import me.chanjar.weixin.mp.bean.WxMpMaterialNews;
|
||||
import me.chanjar.weixin.mp.bean.result.*;
|
||||
import me.chanjar.weixin.mp.util.http.*;
|
||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
@ -27,6 +28,8 @@ import java.util.UUID;
|
||||
* Created by Binary Wang on 2016/7/21.
|
||||
*/
|
||||
public class WxMpMaterialServiceImpl implements WxMpMaterialService {
|
||||
private static final String MEDIA_API_URL_PREFIX = "https://api.weixin.qq.com/cgi-bin/qrcode";
|
||||
private static final String MATERIAL_API_URL_PREFIX = "https://api.weixin.qq.com/cgi-bin/qrcode";
|
||||
private WxMpService wxMpService;
|
||||
|
||||
public WxMpMaterialServiceImpl(WxMpService wxMpService) {
|
||||
@ -40,19 +43,25 @@ public class WxMpMaterialServiceImpl implements WxMpMaterialService {
|
||||
|
||||
@Override
|
||||
public WxMediaUploadResult mediaUpload(String mediaType, File file) throws WxErrorException {
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/media/upload?type=" + mediaType;
|
||||
String url = MEDIA_API_URL_PREFIX + "/upload?type=" + mediaType;
|
||||
return this.wxMpService.execute(new MediaUploadRequestExecutor(), url, file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public File mediaDownload(String media_id) throws WxErrorException {
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/media/get";
|
||||
String url = MEDIA_API_URL_PREFIX + "/get";
|
||||
return this.wxMpService.execute(new MediaDownloadRequestExecutor(this.wxMpService.getWxMpConfigStorage().getTmpDirFile()), url, "media_id=" + media_id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMediaImgUploadResult mediaImgUpload(File file) throws WxErrorException {
|
||||
String url = MEDIA_API_URL_PREFIX + "/uploadimg";
|
||||
return this.wxMpService.execute(new MediaImgUploadRequestExecutor(), url, file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpMaterialUploadResult materialFileUpload(String mediaType, WxMpMaterial material) throws WxErrorException {
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/material/add_material?type=" + mediaType;
|
||||
String url = MATERIAL_API_URL_PREFIX + "/add_material?type=" + mediaType;
|
||||
return this.wxMpService.execute(new MaterialUploadRequestExecutor(), url, material);
|
||||
}
|
||||
|
||||
@ -61,32 +70,32 @@ public class WxMpMaterialServiceImpl implements WxMpMaterialService {
|
||||
if (news == null || news.isEmpty()) {
|
||||
throw new IllegalArgumentException("news is empty!");
|
||||
}
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/material/add_news";
|
||||
String url = MATERIAL_API_URL_PREFIX + "/add_news";
|
||||
String responseContent = this.wxMpService.post(url, news.toJson());
|
||||
return WxMpMaterialUploadResult.fromJson(responseContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream materialImageOrVoiceDownload(String media_id) throws WxErrorException {
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/material/get_material";
|
||||
String url = MATERIAL_API_URL_PREFIX + "/get_material";
|
||||
return this.wxMpService.execute(new MaterialVoiceAndImageDownloadRequestExecutor(this.wxMpService.getWxMpConfigStorage().getTmpDirFile()), url, media_id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpMaterialVideoInfoResult materialVideoInfo(String media_id) throws WxErrorException {
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/material/get_material";
|
||||
String url = MATERIAL_API_URL_PREFIX + "/get_material";
|
||||
return this.wxMpService.execute(new MaterialVideoInfoRequestExecutor(), url, media_id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpMaterialNews materialNewsInfo(String media_id) throws WxErrorException {
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/material/get_material";
|
||||
String url = MATERIAL_API_URL_PREFIX + "/get_material";
|
||||
return this.wxMpService.execute(new MaterialNewsInfoRequestExecutor(), url, media_id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean materialNewsUpdate(WxMpMaterialArticleUpdate wxMpMaterialArticleUpdate) throws WxErrorException {
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/material/update_news";
|
||||
String url = MATERIAL_API_URL_PREFIX + "/update_news";
|
||||
String responseText = this.wxMpService.post(url, wxMpMaterialArticleUpdate.toJson());
|
||||
WxError wxError = WxError.fromJson(responseText);
|
||||
if (wxError.getErrorCode() == 0) {
|
||||
@ -98,13 +107,13 @@ public class WxMpMaterialServiceImpl implements WxMpMaterialService {
|
||||
|
||||
@Override
|
||||
public boolean materialDelete(String media_id) throws WxErrorException {
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/material/del_material";
|
||||
String url = MATERIAL_API_URL_PREFIX + "/del_material";
|
||||
return this.wxMpService.execute(new MaterialDeleteRequestExecutor(), url, media_id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpMaterialCountResult materialCount() throws WxErrorException {
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/material/get_materialcount";
|
||||
String url = MATERIAL_API_URL_PREFIX + "/get_materialcount";
|
||||
String responseText = this.wxMpService.get(url, null);
|
||||
WxError wxError = WxError.fromJson(responseText);
|
||||
if (wxError.getErrorCode() == 0) {
|
||||
@ -116,7 +125,7 @@ public class WxMpMaterialServiceImpl implements WxMpMaterialService {
|
||||
|
||||
@Override
|
||||
public WxMpMaterialNewsBatchGetResult materialNewsBatchGet(int offset, int count) throws WxErrorException {
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/material/batchget_material";
|
||||
String url = MATERIAL_API_URL_PREFIX + "/batchget_material";
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("type", WxConsts.MATERIAL_NEWS);
|
||||
params.put("offset", offset);
|
||||
@ -132,7 +141,7 @@ public class WxMpMaterialServiceImpl implements WxMpMaterialService {
|
||||
|
||||
@Override
|
||||
public WxMpMaterialFileBatchGetResult materialFileBatchGet(String type, int offset, int count) throws WxErrorException {
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/material/batchget_material";
|
||||
String url = MATERIAL_API_URL_PREFIX + "/batchget_material";
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("type", type);
|
||||
params.put("offset", offset);
|
||||
@ -146,10 +155,4 @@ public class WxMpMaterialServiceImpl implements WxMpMaterialService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMediaImgUploadResult mediaImgUpload(File file) throws WxErrorException {
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/media/uploadimg";
|
||||
return this.wxMpService.execute(new MediaImgUploadRequestExecutor(), url, file);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,102 @@
|
||||
package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import me.chanjar.weixin.common.bean.result.WxError;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
|
||||
import me.chanjar.weixin.mp.api.WxMpQrcodeService;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;
|
||||
import me.chanjar.weixin.mp.util.http.QrCodeRequestExecutor;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* Created by Binary Wang on 2016/7/21.
|
||||
*/
|
||||
public class WxMpQrcodeServiceImpl implements WxMpQrcodeService {
|
||||
private static final String API_URL_PREFIX = "https://api.weixin.qq.com/cgi-bin/qrcode";
|
||||
private WxMpService wxMpService;
|
||||
|
||||
public WxMpQrcodeServiceImpl(WxMpService wxMpService) {
|
||||
this.wxMpService = wxMpService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpQrCodeTicket qrCodeCreateTmpTicket(int scene_id, Integer expire_seconds) throws WxErrorException {
|
||||
String url = API_URL_PREFIX + "/create";
|
||||
JsonObject json = new JsonObject();
|
||||
json.addProperty("action_name", "QR_SCENE");
|
||||
if (expire_seconds != null) {
|
||||
json.addProperty("expire_seconds", expire_seconds);
|
||||
}
|
||||
JsonObject actionInfo = new JsonObject();
|
||||
JsonObject scene = new JsonObject();
|
||||
scene.addProperty("scene_id", scene_id);
|
||||
actionInfo.add("scene", scene);
|
||||
json.add("action_info", actionInfo);
|
||||
String responseContent = this.wxMpService.execute(new SimplePostRequestExecutor(), url, json.toString());
|
||||
return WxMpQrCodeTicket.fromJson(responseContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpQrCodeTicket qrCodeCreateLastTicket(int scene_id) throws WxErrorException {
|
||||
String url = API_URL_PREFIX + "/create";
|
||||
JsonObject json = new JsonObject();
|
||||
json.addProperty("action_name", "QR_LIMIT_SCENE");
|
||||
JsonObject actionInfo = new JsonObject();
|
||||
JsonObject scene = new JsonObject();
|
||||
scene.addProperty("scene_id", scene_id);
|
||||
actionInfo.add("scene", scene);
|
||||
json.add("action_info", actionInfo);
|
||||
String responseContent = this.wxMpService.execute(new SimplePostRequestExecutor(), url, json.toString());
|
||||
return WxMpQrCodeTicket.fromJson(responseContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpQrCodeTicket qrCodeCreateLastTicket(String scene_str) throws WxErrorException {
|
||||
String url = API_URL_PREFIX + "/create";
|
||||
JsonObject json = new JsonObject();
|
||||
json.addProperty("action_name", "QR_LIMIT_STR_SCENE");
|
||||
JsonObject actionInfo = new JsonObject();
|
||||
JsonObject scene = new JsonObject();
|
||||
scene.addProperty("scene_str", scene_str);
|
||||
actionInfo.add("scene", scene);
|
||||
json.add("action_info", actionInfo);
|
||||
String responseContent = this.wxMpService.execute(new SimplePostRequestExecutor(), url, json.toString());
|
||||
return WxMpQrCodeTicket.fromJson(responseContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public File qrCodePicture(WxMpQrCodeTicket ticket) throws WxErrorException {
|
||||
String url = "https://mp.weixin.qq.com/cgi-bin/showqrcode";
|
||||
return this.wxMpService.execute(new QrCodeRequestExecutor(), url, ticket);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String qrCodePictureUrl(String ticket, boolean needShortUrl) throws WxErrorException {
|
||||
String url = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=%s";
|
||||
try {
|
||||
String resultUrl = String.format(url,
|
||||
URLEncoder.encode(ticket, StandardCharsets.UTF_8.name()));
|
||||
if (needShortUrl) {
|
||||
return this.wxMpService.shortUrl(resultUrl);
|
||||
}
|
||||
|
||||
return resultUrl;
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
WxError error = WxError.newBuilder().setErrorCode(-1)
|
||||
.setErrorMsg(e.getMessage()).build();
|
||||
throw new WxErrorException(error);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String qrCodePictureUrl(String ticket) throws WxErrorException {
|
||||
return qrCodePictureUrl(ticket, false);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.internal.Streams;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
|
||||
import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.api.WxMpUserService;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUser;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUserCumulate;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUserList;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUserSummary;
|
||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Binary Wang on 2016/7/21.
|
||||
*/
|
||||
public class WxMpUserServiceImpl implements WxMpUserService {
|
||||
private static final String API_URL_PREFIX = "https://api.weixin.qq.com/cgi-bin/user";
|
||||
private WxMpService wxMpService;
|
||||
|
||||
public WxMpUserServiceImpl(WxMpService wxMpService) {
|
||||
this.wxMpService = wxMpService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void userUpdateRemark(String openid, String remark) throws WxErrorException {
|
||||
String url = API_URL_PREFIX + "/info/updateremark";
|
||||
JsonObject json = new JsonObject();
|
||||
json.addProperty("openid", openid);
|
||||
json.addProperty("remark", remark);
|
||||
this.wxMpService.execute(new SimplePostRequestExecutor(), url, json.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpUser userInfo(String openid, String lang) throws WxErrorException {
|
||||
String url = API_URL_PREFIX + "/info";
|
||||
lang = lang == null ? "zh_CN" : lang;
|
||||
String responseContent = this.wxMpService.execute(new SimpleGetRequestExecutor(), url, "openid=" + openid + "&lang=" + lang);
|
||||
return WxMpUser.fromJson(responseContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpUserList userList(String next_openid) throws WxErrorException {
|
||||
String url = API_URL_PREFIX + "/get";
|
||||
String responseContent = this.wxMpService.execute(new SimpleGetRequestExecutor(), url, next_openid == null ? null : "next_openid=" + next_openid);
|
||||
return WxMpUserList.fromJson(responseContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WxMpUserSummary> dataCubeUserSummary(Date beginDate, Date endDate) throws WxErrorException {
|
||||
String url = "https://api.weixin.qq.com/datacube/getusersummary";
|
||||
JsonObject param = new JsonObject();
|
||||
param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate));
|
||||
param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate));
|
||||
String responseContent = this.wxMpService.post(url, param.toString());
|
||||
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
|
||||
return WxMpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement.getAsJsonObject().get("list"),
|
||||
new TypeToken<List<WxMpUserSummary>>() {
|
||||
}.getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WxMpUserCumulate> dataCubeUserCumulate(Date beginDate, Date endDate) throws WxErrorException {
|
||||
String url = "https://api.weixin.qq.com/datacube/getusercumulate";
|
||||
JsonObject param = new JsonObject();
|
||||
param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate));
|
||||
param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate));
|
||||
String responseContent = this.wxMpService.post(url, param.toString());
|
||||
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
|
||||
return WxMpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement.getAsJsonObject().get("list"),
|
||||
new TypeToken<List<WxMpUserCumulate>>() {
|
||||
}.getType());
|
||||
}
|
||||
}
|
@ -45,4 +45,9 @@ public class WxMpQrCodeTicket implements Serializable {
|
||||
public static WxMpQrCodeTicket fromJson(String json) {
|
||||
return WxMpGsonBuilder.INSTANCE.create().fromJson(json, WxMpQrCodeTicket.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return WxMpGsonBuilder.INSTANCE.create().toJson(this);
|
||||
}
|
||||
}
|
||||
|
@ -44,4 +44,9 @@ public class WxMpUserList {
|
||||
public static WxMpUserList fromJson(String json) {
|
||||
return WxMpGsonBuilder.INSTANCE.create().fromJson(json, WxMpUserList.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return WxMpGsonBuilder.INSTANCE.create().toJson(this);
|
||||
}
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ public class WxMpMassMessageAPITest {
|
||||
WxMpMassGroupMessage massMessage = new WxMpMassGroupMessage();
|
||||
massMessage.setMsgtype(WxConsts.MASS_MSG_TEXT);
|
||||
massMessage.setContent("测试群发消息\n欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>");
|
||||
massMessage.setGroupId(wxService.groupGet().get(0).getId());
|
||||
massMessage.setGroupId(wxService.getGroupService().groupGet().get(0).getId());
|
||||
|
||||
WxMpMassSendResult massResult = wxService.massGroupMessageSend(massMessage);
|
||||
Assert.assertNotNull(massResult);
|
||||
@ -75,7 +75,7 @@ public class WxMpMassMessageAPITest {
|
||||
WxMpMassGroupMessage massMessage = new WxMpMassGroupMessage();
|
||||
massMessage.setMsgtype(massMsgType);
|
||||
massMessage.setMediaId(mediaId);
|
||||
massMessage.setGroupId(wxService.groupGet().get(0).getId());
|
||||
massMessage.setGroupId(wxService.getGroupService().groupGet().get(0).getId());
|
||||
|
||||
WxMpMassSendResult massResult = wxService.massGroupMessageSend(massMessage);
|
||||
Assert.assertNotNull(massResult);
|
||||
|
@ -1,37 +1,19 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.session.WxSession;
|
||||
import me.chanjar.weixin.mp.bean.WxMpMassGroupMessage;
|
||||
import me.chanjar.weixin.mp.bean.WxMpMassNews;
|
||||
import me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage;
|
||||
import me.chanjar.weixin.mp.bean.WxMpMassVideo;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUserCumulate;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUserSummary;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chanjarster
|
||||
*
|
||||
*/
|
||||
@Test(groups = "miscAPI", dependsOnGroups = { "baseAPI"})
|
||||
@Test(groups = "miscAPI")
|
||||
@Guice(modules = ApiTestModule.class)
|
||||
public class WxMpMiscAPITest {
|
||||
|
||||
@ -46,24 +28,4 @@ public class WxMpMiscAPITest {
|
||||
Assert.assertNotEquals(ipArray.length, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUserSummary() throws WxErrorException, ParseException {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
Date beginDate = simpleDateFormat.parse("2015-01-01");
|
||||
Date endDate = simpleDateFormat.parse("2015-01-02");
|
||||
List<WxMpUserSummary> summaries = wxService.getUserSummary(beginDate, endDate);
|
||||
System.out.println(summaries);
|
||||
Assert.assertNotNull(summaries);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUserCumulate() throws WxErrorException, ParseException {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
Date beginDate = simpleDateFormat.parse("2015-01-01");
|
||||
Date endDate = simpleDateFormat.parse("2015-01-02");
|
||||
List<WxMpUserCumulate> cumulates = wxService.getUserCumulate(beginDate, endDate);
|
||||
System.out.println(cumulates);
|
||||
Assert.assertNotNull(cumulates);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,53 +0,0 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUser;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUserList;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* 测试用户相关的接口
|
||||
* @author chanjarster
|
||||
*
|
||||
*/
|
||||
@Test(groups = "userAPI", dependsOnGroups = { "baseAPI", "groupAPI" })
|
||||
@Guice(modules = ApiTestModule.class)
|
||||
public class WxMpUserAPITest {
|
||||
|
||||
@Inject
|
||||
protected WxMpServiceImpl wxService;
|
||||
|
||||
public void testUserUpdateRemark() throws WxErrorException {
|
||||
ApiTestModule.WxXmlMpInMemoryConfigStorage configProvider = (ApiTestModule.WxXmlMpInMemoryConfigStorage) wxService.wxMpConfigStorage;
|
||||
wxService.userUpdateRemark(configProvider.getOpenId(), "测试备注名");
|
||||
}
|
||||
|
||||
public void testUserInfo() throws WxErrorException {
|
||||
ApiTestModule.WxXmlMpInMemoryConfigStorage configProvider = (ApiTestModule.WxXmlMpInMemoryConfigStorage) wxService.wxMpConfigStorage;
|
||||
WxMpUser user = wxService.userInfo(configProvider.getOpenId(), null);
|
||||
Assert.assertNotNull(user);
|
||||
}
|
||||
|
||||
public void testUserList() throws WxErrorException {
|
||||
WxMpUserList wxMpUserList = wxService.userList(null);
|
||||
Assert.assertNotNull(wxMpUserList);
|
||||
Assert.assertFalse(wxMpUserList.getCount() == -1);
|
||||
Assert.assertFalse(wxMpUserList.getTotal() == -1);
|
||||
Assert.assertFalse(wxMpUserList.getOpenIds().size() == -1);
|
||||
}
|
||||
|
||||
public void testGroupQueryUserGroup() throws WxErrorException {
|
||||
ApiTestModule.WxXmlMpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlMpInMemoryConfigStorage) wxService.wxMpConfigStorage;
|
||||
long groupid = wxService.userGetGroup(configStorage.getOpenId());
|
||||
Assert.assertTrue(groupid != -1l);
|
||||
}
|
||||
|
||||
public void getGroupMoveUser() throws WxErrorException {
|
||||
ApiTestModule.WxXmlMpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlMpInMemoryConfigStorage) wxService.wxMpConfigStorage;
|
||||
wxService.userUpdateGroup(configStorage.getOpenId(), wxService.groupGet().get(3).getId());
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +1,9 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.mp.api.ApiTestModule;
|
||||
import me.chanjar.weixin.mp.api.WxMpServiceImpl;
|
||||
import me.chanjar.weixin.mp.bean.WxMpGroup;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Guice;
|
||||
@ -14,9 +16,9 @@ import java.util.List;
|
||||
*
|
||||
* @author chanjarster
|
||||
*/
|
||||
@Test(groups = "groupAPI", dependsOnGroups = "baseAPI")
|
||||
@Test(groups = "groupAPI")
|
||||
@Guice(modules = ApiTestModule.class)
|
||||
public class WxMpGroupAPITest {
|
||||
public class WxMpGroupServiceImplTest {
|
||||
|
||||
@Inject
|
||||
protected WxMpServiceImpl wxService;
|
||||
@ -24,13 +26,13 @@ public class WxMpGroupAPITest {
|
||||
protected WxMpGroup group;
|
||||
|
||||
public void testGroupCreate() throws WxErrorException {
|
||||
WxMpGroup res = wxService.groupCreate("测试分组1");
|
||||
WxMpGroup res = this.wxService.getGroupService().groupCreate("测试分组1");
|
||||
Assert.assertEquals(res.getName(), "测试分组1");
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods="testGroupCreate")
|
||||
public void testGroupGet() throws WxErrorException {
|
||||
List<WxMpGroup> groupList = wxService.groupGet();
|
||||
List<WxMpGroup> groupList = this.wxService.getGroupService().groupGet();
|
||||
Assert.assertNotNull(groupList);
|
||||
Assert.assertTrue(groupList.size() > 0);
|
||||
for (WxMpGroup g : groupList) {
|
||||
@ -42,7 +44,7 @@ public class WxMpGroupAPITest {
|
||||
@Test(dependsOnMethods={"testGroupGet", "testGroupCreate"})
|
||||
public void getGroupUpdate() throws WxErrorException {
|
||||
group.setName("分组改名");
|
||||
wxService.groupUpdate(group);
|
||||
this.wxService.getGroupService().groupUpdate(group);
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +1,9 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.mp.api.ApiTestModule;
|
||||
import me.chanjar.weixin.mp.api.WxMpServiceImpl;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Guice;
|
||||
@ -16,35 +18,39 @@ import java.io.File;
|
||||
*/
|
||||
@Test(groups = "qrCodeAPI")
|
||||
@Guice(modules = ApiTestModule.class)
|
||||
public class WxMpQrCodeAPITest {
|
||||
public class WxMpQrCodeServiceImplTest {
|
||||
|
||||
@Inject
|
||||
protected WxMpServiceImpl wxService;
|
||||
|
||||
public void testQrCodeCreateTmpTicket() throws WxErrorException {
|
||||
WxMpQrCodeTicket ticket = this.wxService.qrCodeCreateTmpTicket(1, null);
|
||||
WxMpQrCodeTicket ticket = this.wxService.getQrcodeService().qrCodeCreateTmpTicket(1, null);
|
||||
Assert.assertNotNull(ticket.getUrl());
|
||||
Assert.assertNotNull(ticket.getTicket());
|
||||
Assert.assertTrue(ticket.getExpire_seconds() != -1);
|
||||
System.out.println(ticket);
|
||||
}
|
||||
|
||||
public void testQrCodeCreateLastTicket() throws WxErrorException {
|
||||
WxMpQrCodeTicket ticket = this.wxService.qrCodeCreateLastTicket(1);
|
||||
WxMpQrCodeTicket ticket = this.wxService.getQrcodeService().qrCodeCreateLastTicket(1);
|
||||
Assert.assertNotNull(ticket.getUrl());
|
||||
Assert.assertNotNull(ticket.getTicket());
|
||||
Assert.assertTrue(ticket.getExpire_seconds() == -1);
|
||||
System.out.println(ticket);
|
||||
}
|
||||
|
||||
public void testQrCodePicture() throws WxErrorException {
|
||||
WxMpQrCodeTicket ticket = this.wxService.qrCodeCreateLastTicket(1);
|
||||
File file = this.wxService.qrCodePicture(ticket);
|
||||
WxMpQrCodeTicket ticket = this.wxService.getQrcodeService().qrCodeCreateLastTicket(1);
|
||||
File file = this.wxService.getQrcodeService().qrCodePicture(ticket);
|
||||
Assert.assertNotNull(file);
|
||||
System.out.println(file.getAbsolutePath());
|
||||
}
|
||||
|
||||
public void testQrCodePictureUrl() throws WxErrorException {
|
||||
WxMpQrCodeTicket ticket = this.wxService.qrCodeCreateLastTicket(1);
|
||||
String url = this.wxService.qrCodePictureUrl(ticket.getTicket());
|
||||
WxMpQrCodeTicket ticket = this.wxService.getQrcodeService().qrCodeCreateLastTicket(1);
|
||||
String url = this.wxService.getQrcodeService().qrCodePictureUrl(ticket.getTicket());
|
||||
Assert.assertNotNull(url);
|
||||
System.out.println(url);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.mp.api.ApiTestModule;
|
||||
import me.chanjar.weixin.mp.api.WxMpServiceImpl;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUser;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUserCumulate;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUserList;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUserSummary;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 测试用户相关的接口
|
||||
*
|
||||
* @author chanjarster
|
||||
* @author Binary Wang
|
||||
*/
|
||||
@Test(groups = "userAPI")
|
||||
@Guice(modules = ApiTestModule.class)
|
||||
public class WxMpUserServiceImplTest {
|
||||
|
||||
@Inject
|
||||
protected WxMpServiceImpl wxService;
|
||||
|
||||
public void testUserUpdateRemark() throws WxErrorException {
|
||||
ApiTestModule.WxXmlMpInMemoryConfigStorage configProvider = (ApiTestModule.WxXmlMpInMemoryConfigStorage) wxService.getWxMpConfigStorage();
|
||||
this.wxService.getUserService().userUpdateRemark(configProvider.getOpenId(), "测试备注名");
|
||||
}
|
||||
|
||||
public void testUserInfo() throws WxErrorException {
|
||||
ApiTestModule.WxXmlMpInMemoryConfigStorage configProvider = (ApiTestModule.WxXmlMpInMemoryConfigStorage) wxService.getWxMpConfigStorage();
|
||||
WxMpUser user = this.wxService.getUserService().userInfo(configProvider.getOpenId(), null);
|
||||
Assert.assertNotNull(user);
|
||||
System.out.println(user);
|
||||
}
|
||||
|
||||
public void testUserList() throws WxErrorException {
|
||||
WxMpUserList wxMpUserList = this.wxService.getUserService().userList(null);
|
||||
Assert.assertNotNull(wxMpUserList);
|
||||
Assert.assertFalse(wxMpUserList.getCount() == -1);
|
||||
Assert.assertFalse(wxMpUserList.getTotal() == -1);
|
||||
Assert.assertFalse(wxMpUserList.getOpenIds().size() == -1);
|
||||
System.out.println(wxMpUserList);
|
||||
}
|
||||
|
||||
public void testGroupQueryUserGroup() throws WxErrorException {
|
||||
ApiTestModule.WxXmlMpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlMpInMemoryConfigStorage) wxService.getWxMpConfigStorage();
|
||||
long groupid = this.wxService.getGroupService().userGetGroup(configStorage.getOpenId());
|
||||
Assert.assertTrue(groupid != -1l);
|
||||
}
|
||||
|
||||
public void testGroupMoveUser() throws WxErrorException {
|
||||
ApiTestModule.WxXmlMpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlMpInMemoryConfigStorage) wxService.getWxMpConfigStorage();
|
||||
this.wxService.getGroupService().userUpdateGroup(configStorage.getOpenId(), this.wxService.getGroupService().groupGet().get(3).getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUserSummary() throws WxErrorException, ParseException {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
Date beginDate = simpleDateFormat.parse("2015-01-01");
|
||||
Date endDate = simpleDateFormat.parse("2015-01-02");
|
||||
List<WxMpUserSummary> summaries = this.wxService.getUserService().dataCubeUserSummary(beginDate, endDate);
|
||||
Assert.assertNotNull(summaries);
|
||||
System.out.println(summaries);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUserCumulate() throws WxErrorException, ParseException {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
Date beginDate = simpleDateFormat.parse("2015-01-01");
|
||||
Date endDate = simpleDateFormat.parse("2015-01-02");
|
||||
List<WxMpUserCumulate> cumulates = this.wxService.getUserService().dataCubeUserCumulate(beginDate, endDate);
|
||||
Assert.assertNotNull(cumulates);
|
||||
System.out.println(cumulates);
|
||||
}
|
||||
|
||||
}
|
@ -7,10 +7,10 @@
|
||||
<class name="me.chanjar.weixin.mp.api.WxMpBaseAPITest" />
|
||||
<class name="me.chanjar.weixin.mp.api.WxMpCustomMessageAPITest" />
|
||||
<class name="me.chanjar.weixin.mp.api.impl.WxMpMenuAPITest" />
|
||||
<class name="me.chanjar.weixin.mp.api.WxMpGroupAPITest" />
|
||||
<class name="me.chanjar.weixin.mp.api.impl.WxMpGroupServiceImplTest" />
|
||||
<class name="me.chanjar.weixin.mp.api.WxMpMassMessageAPITest" />
|
||||
<class name="me.chanjar.weixin.mp.api.WxMpUserAPITest" />
|
||||
<class name="me.chanjar.weixin.mp.api.WxMpQrCodeAPITest" />
|
||||
<class name="me.chanjar.weixin.mp.api.impl.WxMpUserServiceImplTest" />
|
||||
<class name="me.chanjar.weixin.mp.api.impl.WxMpQrCodeServiceImplTest" />
|
||||
<class name="me.chanjar.weixin.mp.api.WxMpShortUrlAPITest" />
|
||||
<class name="me.chanjar.weixin.mp.api.WxMpMessageRouterTest" />
|
||||
<class name="me.chanjar.weixin.mp.api.WxMpJsAPITest" />
|
||||
|
Loading…
Reference in New Issue
Block a user