主要对jssdk的支持以及别的优化(:
This commit is contained in:
parent
b7376d7d6b
commit
73c6aaf05a
21
CHANGE.md
21
CHANGE.md
@ -563,3 +563,24 @@
|
||||
* 2015-12-21
|
||||
|
||||
+ weixin4j-server:WeixinMessageHanlder中新增weight接口
|
||||
|
||||
|
||||
* 2015-12-25
|
||||
|
||||
+ weixin4j-base:WeixinPayProxy类新增获取支付信息#getWeixinAccount方法
|
||||
|
||||
+ weixin4j-base:新增JSSDK的config生成类
|
||||
|
||||
+ weixin4j-mp:WeixinProxy新增获取appid(getAppId)方法
|
||||
|
||||
+ weixin4j-mp:WeixinProxy新增获取jsticket(getJSTicketHolder)方法
|
||||
|
||||
+ weixin4j-mp:私有化WeixinProxy(TokenHolder)构造器
|
||||
|
||||
+ weixin4j-qy:WeixinProxy新增获取corpid(getCorpId)方法
|
||||
|
||||
+ weixin4j-qy:WeixinProxy新增获取jsticket(getJSTicketHolder)方法
|
||||
|
||||
+ weixin4j-qy:私有化WeixinProxy(TokenHolder)构造器
|
||||
|
||||
+ weixin4j-qy:SuiteApi新增获取Weixinproxy对象(getWeixinProxy)方法
|
||||
|
||||
@ -52,6 +52,8 @@ public class WeixinPayProxy {
|
||||
private final CouponApi couponApi;
|
||||
private final CashApi cashApi;
|
||||
|
||||
private final WeixinPayAccount weixinAccount;
|
||||
|
||||
/**
|
||||
* 使用weixin4j.properties配置的账号信息
|
||||
*/
|
||||
@ -67,11 +69,23 @@ public class WeixinPayProxy {
|
||||
*
|
||||
*/
|
||||
public WeixinPayProxy(WeixinPayAccount weixinAccount) {
|
||||
this.weixinAccount = weixinAccount;
|
||||
this.pay3Api = new Pay3Api(weixinAccount);
|
||||
this.couponApi = new CouponApi(weixinAccount);
|
||||
this.cashApi = new CashApi(weixinAccount);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取微信商户支付信息
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public WeixinPayAccount getWeixinAccount() {
|
||||
// clone ...
|
||||
String text = JSON.toJSONString(weixinAccount);
|
||||
return JSON.parseObject(text, WeixinPayAccount.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 统一下单接口</br>
|
||||
* 除被扫支付场景以外,商户系统先调用该接口在微信支付服务后台生成预支付交易单,返回正确的预支付交易回话标识后再按扫码、JSAPI
|
||||
|
||||
@ -14,7 +14,7 @@ import com.foxinmy.weixin4j.model.Token;
|
||||
*/
|
||||
public interface TokenCreator {
|
||||
/**
|
||||
* 返回缓存KEY的名称:Prefix+UniqueId的组合
|
||||
* 返回缓存KEY的名称
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
|
||||
@ -74,4 +74,8 @@ public class TokenHolder {
|
||||
tokenStorager.caching(cacheKey, token);
|
||||
return token;
|
||||
}
|
||||
|
||||
public TokenStorager getTokenStorager() {
|
||||
return tokenStorager;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,305 @@
|
||||
package com.foxinmy.weixin4j.util;
|
||||
|
||||
/**
|
||||
* JSSDK接口列表
|
||||
*
|
||||
* @className JSSDKAPIs
|
||||
* @author jy
|
||||
* @date 2015年12月23日
|
||||
* @since JDK 1.7
|
||||
* @see
|
||||
*/
|
||||
public enum JSSDKAPI {
|
||||
/***
|
||||
* <a href=
|
||||
* "http://mp.weixin.qq.com/wiki/11/74ad127cc054f6b80759c40f77ec03db.html#.E8.8E.B7.E5.8F.96.E2.80.9C.E5.88.86.E4.BA.AB.E5.88.B0.E6.9C.8B.E5.8F.8B.E5.9C.88.E2.80.9D.E6.8C.89.E9.92.AE.E7.82.B9.E5.87.BB.E7.8A.B6.E6.80.81.E5.8F.8A.E8.87.AA.E5.AE.9A.E4.B9.89.E5.88.86.E4.BA.AB.E5.86.85.E5.AE.B9.E6.8E.A5.E5.8F.A3"
|
||||
* >分享接口-获取“分享到朋友圈”按钮点击状态及自定义分享内容接口</a>
|
||||
*/
|
||||
onMenuShareTimeline,
|
||||
/***
|
||||
* <a href=
|
||||
* "http://mp.weixin.qq.com/wiki/11/74ad127cc054f6b80759c40f77ec03db.html#.E8.8E.B7.E5.8F.96.E2.80.9C.E5.88.86.E4.BA.AB.E7.BB.99.E6.9C.8B.E5.8F.8B.E2.80.9D.E6.8C.89.E9.92.AE.E7.82.B9.E5.87.BB.E7.8A.B6.E6.80.81.E5.8F.8A.E8.87.AA.E5.AE.9A.E4.B9.89.E5.88.86.E4.BA.AB.E5.86.85.E5.AE.B9.E6.8E.A5.E5.8F.A3"
|
||||
* >分享接口-获取“分享给朋友”按钮点击状态及自定义分享内容接口</a>
|
||||
*/
|
||||
onMenuShareAppMessage,
|
||||
/***
|
||||
* <a href=
|
||||
* "http://mp.weixin.qq.com/wiki/11/74ad127cc054f6b80759c40f77ec03db.html#.E8.8E.B7.E5.8F.96.E2.80.9C.E5.88.86.E4.BA.AB.E5.88.B0QQ.E2.80.9D.E6.8C.89.E9.92.AE.E7.82.B9.E5.87.BB.E7.8A.B6.E6.80.81.E5.8F.8A.E8.87.AA.E5.AE.9A.E4.B9.89.E5.88.86.E4.BA.AB.E5.86.85.E5.AE.B9.E6.8E.A5.E5.8F.A3"
|
||||
* >分享接口-获取“分享到QQ”按钮点击状态及自定义分享内容接口</a>
|
||||
*/
|
||||
onMenuShareQQ,
|
||||
/***
|
||||
* <a href=
|
||||
* "http://mp.weixin.qq.com/wiki/11/74ad127cc054f6b80759c40f77ec03db.html#.E8.8E.B7.E5.8F.96.E2.80.9C.E5.88.86.E4.BA.AB.E5.88.B0.E8.85.BE.E8.AE.AF.E5.BE.AE.E5.8D.9A.E2.80.9D.E6.8C.89.E9.92.AE.E7.82.B9.E5.87.BB.E7.8A.B6.E6.80.81.E5.8F.8A.E8.87.AA.E5.AE.9A.E4.B9.89.E5.88.86.E4.BA.AB.E5.86.85.E5.AE.B9.E6.8E.A5.E5.8F.A3"
|
||||
* >分享接口-获取“分享到腾讯微博”按钮点击状态及自定义分享内容接口</a>
|
||||
*/
|
||||
onMenuShareWeibo,
|
||||
/***
|
||||
* <a href=
|
||||
* "http://mp.weixin.qq.com/wiki/11/74ad127cc054f6b80759c40f77ec03db.html#.E8.8E.B7.E5.8F.96.E2.80.9C.E5.88.86.E4.BA.AB.E5.88.B0QQ.E7.A9.BA.E9.97.B4.E2.80.9D.E6.8C.89.E9.92.AE.E7.82.B9.E5.87.BB.E7.8A.B6.E6.80.81.E5.8F.8A.E8.87.AA.E5.AE.9A.E4.B9.89.E5.88.86.E4.BA.AB.E5.86.85.E5.AE.B9.E6.8E.A5.E5.8F.A3"
|
||||
* >分享接口-获取“分享到QQ空间”按钮点击状态及自定义分享内容接口</a>
|
||||
*/
|
||||
onMenuShareQZone,
|
||||
/***
|
||||
* <a href=
|
||||
* "http://mp.weixin.qq.com/wiki/11/74ad127cc054f6b80759c40f77ec03db.html#.E6.8B.8D.E7.85.A7.E6.88.96.E4.BB.8E.E6.89.8B.E6.9C.BA.E7.9B.B8.E5.86.8C.E4.B8.AD.E9.80.89.E5.9B.BE.E6.8E.A5.E5.8F.A3"
|
||||
* >图像接口-拍照或从手机相册中选图接口</a>
|
||||
*/
|
||||
chooseImage,
|
||||
/***
|
||||
* <a href=
|
||||
* "http://mp.weixin.qq.com/wiki/11/74ad127cc054f6b80759c40f77ec03db.html#.E9.A2.84.E8.A7.88.E5.9B.BE.E7.89.87.E6.8E.A5.E5.8F.A3"
|
||||
* >图像接口-预览图片接口</a>
|
||||
*/
|
||||
previewImage,
|
||||
/***
|
||||
* <a href=
|
||||
* "http://mp.weixin.qq.com/wiki/11/74ad127cc054f6b80759c40f77ec03db.html#.E4.B8.8A.E4.BC.A0.E5.9B.BE.E7.89.87.E6.8E.A5.E5.8F.A3"
|
||||
* >图像接口-上传图片接口</a>
|
||||
*/
|
||||
uploadImage,
|
||||
/***
|
||||
* <a href=
|
||||
* "http://mp.weixin.qq.com/wiki/11/74ad127cc054f6b80759c40f77ec03db.html#.E4.B8.8B.E8.BD.BD.E5.9B.BE.E7.89.87.E6.8E.A5.E5.8F.A3"
|
||||
* >图像接口-下载图片接口</a>
|
||||
*/
|
||||
downloadImage,
|
||||
/***
|
||||
* <a href=
|
||||
* "http://mp.weixin.qq.com/wiki/11/74ad127cc054f6b80759c40f77ec03db.html#.E5.BC.80.E5.A7.8B.E5.BD.95.E9.9F.B3.E6.8E.A5.E5.8F.A3"
|
||||
* >音频接口-开始录音接口</a>
|
||||
*/
|
||||
startRecord,
|
||||
/***
|
||||
* <a href=
|
||||
* "http://mp.weixin.qq.com/wiki/11/74ad127cc054f6b80759c40f77ec03db.html#.E5.81.9C.E6.AD.A2.E5.BD.95.E9.9F.B3.E6.8E.A5.E5.8F.A3"
|
||||
* >音频接口-停止录音接口</a>
|
||||
*/
|
||||
stopRecord,
|
||||
/***
|
||||
* <a href=
|
||||
* "http://mp.weixin.qq.com/wiki/11/74ad127cc054f6b80759c40f77ec03db.html#.E7.9B.91.E5.90.AC.E5.BD.95.E9.9F.B3.E8.87.AA.E5.8A.A8.E5.81.9C.E6.AD.A2.E6.8E.A5.E5.8F.A3"
|
||||
* >音频接口-监听录音自动停止接口</a>
|
||||
*/
|
||||
onVoiceRecordEnd,
|
||||
/***
|
||||
* <a href=
|
||||
* "http://mp.weixin.qq.com/wiki/11/74ad127cc054f6b80759c40f77ec03db.html#.E6.92.AD.E6.94.BE.E8.AF.AD.E9.9F.B3.E6.8E.A5.E5.8F.A3"
|
||||
* >音频接口-播放语音接口</a>
|
||||
*/
|
||||
playVoice,
|
||||
/***
|
||||
* <a href=
|
||||
* "http://mp.weixin.qq.com/wiki/11/74ad127cc054f6b80759c40f77ec03db.html#.E6.9A.82.E5.81.9C.E6.92.AD.E6.94.BE.E6.8E.A5.E5.8F.A3"
|
||||
* >音频接口-暂停播放接口</a>
|
||||
*/
|
||||
pauseVoice,
|
||||
/***
|
||||
* <a href=
|
||||
* "http://mp.weixin.qq.com/wiki/11/74ad127cc054f6b80759c40f77ec03db.html#.E5.81.9C.E6.AD.A2.E6.92.AD.E6.94.BE.E6.8E.A5.E5.8F.A3"
|
||||
* >音频接口-停止播放接口</a>
|
||||
*/
|
||||
stopVoice,
|
||||
/***
|
||||
* <a href=
|
||||
* "http://mp.weixin.qq.com/wiki/11/74ad127cc054f6b80759c40f77ec03db.html#.E7.9B.91.E5.90.AC.E8.AF.AD.E9.9F.B3.E6.92.AD.E6.94.BE.E5.AE.8C.E6.AF.95.E6.8E.A5.E5.8F.A3"
|
||||
* >音频接口-监听语音播放完毕接口</a>
|
||||
*/
|
||||
onVoicePlayEnd,
|
||||
/***
|
||||
* <a href=
|
||||
* "http://mp.weixin.qq.com/wiki/11/74ad127cc054f6b80759c40f77ec03db.html#.E4.B8.8A.E4.BC.A0.E8.AF.AD.E9.9F.B3.E6.8E.A5.E5.8F.A3"
|
||||
* >音频接口-上传语音接口</a>
|
||||
*/
|
||||
uploadVoice,
|
||||
/***
|
||||
* <a href=
|
||||
* "http://mp.weixin.qq.com/wiki/11/74ad127cc054f6b80759c40f77ec03db.html#.E4.B8.8B.E8.BD.BD.E8.AF.AD.E9.9F.B3.E6.8E.A5.E5.8F.A3"
|
||||
* >音频接口-下载语音接口</a>
|
||||
*/
|
||||
downloadVoice,
|
||||
/***
|
||||
* <a href=
|
||||
* "http://mp.weixin.qq.com/wiki/11/74ad127cc054f6b80759c40f77ec03db.html#.E8.AF.86.E5.88.AB.E9.9F.B3.E9.A2.91.E5.B9.B6.E8.BF.94.E5.9B.9E.E8.AF.86.E5.88.AB.E7.BB.93.E6.9E.9C.E6.8E.A5.E5.8F.A3"
|
||||
* >智能接口-识别音频并返回识别结果接口</a>
|
||||
*/
|
||||
translateVoice,
|
||||
/***
|
||||
* <a href=
|
||||
* "http://mp.weixin.qq.com/wiki/11/74ad127cc054f6b80759c40f77ec03db.html#.E8.8E.B7.E5.8F.96.E7.BD.91.E7.BB.9C.E7.8A.B6.E6.80.81.E6.8E.A5.E5.8F.A3"
|
||||
* >设备信息-获取网络状态接口</a>
|
||||
*/
|
||||
getNetworkType,
|
||||
/***
|
||||
* <a href=
|
||||
* "http://mp.weixin.qq.com/wiki/11/74ad127cc054f6b80759c40f77ec03db.html#.E4.BD.BF.E7.94.A8.E5.BE.AE.E4.BF.A1.E5.86.85.E7.BD.AE.E5.9C.B0.E5.9B.BE.E6.9F.A5.E7.9C.8B.E4.BD.8D.E7.BD.AE.E6.8E.A5.E5.8F.A3"
|
||||
* >地理位置-使用微信内置地图查看位置接口</a>
|
||||
*/
|
||||
openLocation,
|
||||
/***
|
||||
* <a href=
|
||||
* "http://mp.weixin.qq.com/wiki/11/74ad127cc054f6b80759c40f77ec03db.html#.E8.8E.B7.E5.8F.96.E5.9C.B0.E7.90.86.E4.BD.8D.E7.BD.AE.E6.8E.A5.E5.8F.A3"
|
||||
* >地理位置-获取地理位置接口</a>
|
||||
*/
|
||||
getLocation,
|
||||
/***
|
||||
* <a href=
|
||||
* "http://mp.weixin.qq.com/wiki/11/74ad127cc054f6b80759c40f77ec03db.html#.E5.BC.80.E5.90.AF.E6.9F.A5.E6.89.BE.E5.91.A8.E8.BE.B9ibeacon.E8.AE.BE.E5.A4.87.E6.8E.A5.E5.8F.A3"
|
||||
* >摇一摇周边-开启查找周边ibeacon设备接口</a>
|
||||
*/
|
||||
startSearchBeacons,
|
||||
/***
|
||||
* <a href=
|
||||
* "http://mp.weixin.qq.com/wiki/11/74ad127cc054f6b80759c40f77ec03db.html#.E5.85.B3.E9.97.AD.E6.9F.A5.E6.89.BE.E5.91.A8.E8.BE.B9ibeacon.E8.AE.BE.E5.A4.87.E6.8E.A5.E5.8F.A3"
|
||||
* >摇一摇周边-关闭查找周边ibeacon设备接口</a>
|
||||
*/
|
||||
stopSearchBeacons,
|
||||
/***
|
||||
* <a href=
|
||||
* "http://mp.weixin.qq.com/wiki/11/74ad127cc054f6b80759c40f77ec03db.html#.E7.9B.91.E5.90.AC.E5.91.A8.E8.BE.B9ibeacon.E8.AE.BE.E5.A4.87.E6.8E.A5.E5.8F.A3"
|
||||
* >摇一摇周边-监听周边ibeacon设备接口</a>
|
||||
*/
|
||||
onSearchBeacons,
|
||||
/***
|
||||
* <a href=
|
||||
* "http://mp.weixin.qq.com/wiki/11/74ad127cc054f6b80759c40f77ec03db.html#.E9.9A.90.E8.97.8F.E5.8F.B3.E4.B8.8A.E8.A7.92.E8.8F.9C.E5.8D.95.E6.8E.A5.E5.8F.A3"
|
||||
* >界面操作-隐藏右上角菜单接口</a>
|
||||
*/
|
||||
hideOptionMenu,
|
||||
/***
|
||||
* <a href=
|
||||
* "http://mp.weixin.qq.com/wiki/11/74ad127cc054f6b80759c40f77ec03db.html#.E6.98.BE.E7.A4.BA.E5.8F.B3.E4.B8.8A.E8.A7.92.E8.8F.9C.E5.8D.95.E6.8E.A5.E5.8F.A3"
|
||||
* >界面操作-显示右上角菜单接口</a>
|
||||
*/
|
||||
showOptionMenu,
|
||||
/***
|
||||
* <a href=
|
||||
* "http://mp.weixin.qq.com/wiki/11/74ad127cc054f6b80759c40f77ec03db.html#.E5.85.B3.E9.97.AD.E5.BD.93.E5.89.8D.E7.BD.91.E9.A1.B5.E7.AA.97.E5.8F.A3.E6.8E.A5.E5.8F.A3"
|
||||
* >界面操作-关闭当前网页窗口接口</a>
|
||||
*/
|
||||
closeWindow,
|
||||
/***
|
||||
* <a href=
|
||||
* "http://mp.weixin.qq.com/wiki/11/74ad127cc054f6b80759c40f77ec03db.html#.E6.89.B9.E9.87.8F.E9.9A.90.E8.97.8F.E5.8A.9F.E8.83.BD.E6.8C.89.E9.92.AE.E6.8E.A5.E5.8F.A3"
|
||||
* >界面操作-批量隐藏功能按钮接口</a>
|
||||
*/
|
||||
hideMenuItems,
|
||||
/***
|
||||
* <a href=
|
||||
* "http://mp.weixin.qq.com/wiki/11/74ad127cc054f6b80759c40f77ec03db.html#.E6.89.B9.E9.87.8F.E6.98.BE.E7.A4.BA.E5.8A.9F.E8.83.BD.E6.8C.89.E9.92.AE.E6.8E.A5.E5.8F.A3"
|
||||
* >界面操作-批量显示功能按钮接口</a>
|
||||
*/
|
||||
showMenuItems,
|
||||
/***
|
||||
* <a href=
|
||||
* "http://mp.weixin.qq.com/wiki/11/74ad127cc054f6b80759c40f77ec03db.html#.E9.9A.90.E8.97.8F.E6.89.80.E6.9C.89.E9.9D.9E.E5.9F.BA.E7.A1.80.E6.8C.89.E9.92.AE.E6.8E.A5.E5.8F.A3"
|
||||
* >界面操作-隐藏所有非基础按钮接口</a>
|
||||
*/
|
||||
hideAllNonBaseMenuItem,
|
||||
/***
|
||||
* <a href=
|
||||
* "http://mp.weixin.qq.com/wiki/11/74ad127cc054f6b80759c40f77ec03db.html#.E6.98.BE.E7.A4.BA.E6.89.80.E6.9C.89.E5.8A.9F.E8.83.BD.E6.8C.89.E9.92.AE.E6.8E.A5.E5.8F.A3"
|
||||
* >界面操作-显示所有功能按钮接口</a>
|
||||
*/
|
||||
showAllNonBaseMenuItem,
|
||||
/***
|
||||
* <a href=
|
||||
* "http://mp.weixin.qq.com/wiki/11/74ad127cc054f6b80759c40f77ec03db.html#.E8.B0.83.E8.B5.B7.E5.BE.AE.E4.BF.A1.E6.89.AB.E4.B8.80.E6.89.AB.E6.8E.A5.E5.8F.A3"
|
||||
* >微信扫一扫-调起微信扫一扫接口</a>
|
||||
*/
|
||||
scanQRCode,
|
||||
/***
|
||||
* <a href=
|
||||
* "http://mp.weixin.qq.com/wiki/11/74ad127cc054f6b80759c40f77ec03db.html#.E8.B7.B3.E8.BD.AC.E5.BE.AE.E4.BF.A1.E5.95.86.E5.93.81.E9.A1.B5.E6.8E.A5.E5.8F.A3"
|
||||
* >微信小店-跳转微信商品页接口</a>
|
||||
*/
|
||||
openProductSpecificView,
|
||||
/***
|
||||
* <a href=
|
||||
* "http://mp.weixin.qq.com/wiki/11/74ad127cc054f6b80759c40f77ec03db.html#.E6.8B.89.E5.8F.96.E9.80.82.E7.94.A8.E5.8D.A1.E5.88.B8.E5.88.97.E8.A1.A8.E5.B9.B6.E8.8E.B7.E5.8F.96.E7.94.A8.E6.88.B7.E9.80.89.E6.8B.A9.E4.BF.A1.E6.81.AF"
|
||||
* >微信卡券-拉取适用卡券列表并获取用户选择信息</a>
|
||||
*/
|
||||
chooseCard,
|
||||
/***
|
||||
* <a href=
|
||||
* "http://mp.weixin.qq.com/wiki/11/74ad127cc054f6b80759c40f77ec03db.html#.E6.89.B9.E9.87.8F.E6.B7.BB.E5.8A.A0.E5.8D.A1.E5.88.B8.E6.8E.A5.E5.8F.A3"
|
||||
* >微信卡券-批量添加卡券接口</a>
|
||||
*/
|
||||
addCard,
|
||||
/***
|
||||
* <a href=
|
||||
* "http://mp.weixin.qq.com/wiki/11/74ad127cc054f6b80759c40f77ec03db.html#.E6.9F.A5.E7.9C.8B.E5.BE.AE.E4.BF.A1.E5.8D.A1.E5.8C.85.E4.B8.AD.E7.9A.84.E5.8D.A1.E5.88.B8.E6.8E.A5.E5.8F.A3"
|
||||
* >微信卡券-查看微信卡包中的卡券接口</a>
|
||||
*/
|
||||
openCard,
|
||||
/***
|
||||
* <a href=
|
||||
* "http://mp.weixin.qq.com/wiki/11/74ad127cc054f6b80759c40f77ec03db.html#.E6.A0.B8.E9.94.80.E5.90.8E.E5.86.8D.E6.AC.A1.E8.B5.A0.E9.80.81.E5.8D.A1.E5.88.B8.E6.8E.A5.E5.8F.A3"
|
||||
* >微信卡券-核销后再次赠送卡券接口</a>
|
||||
*/
|
||||
consumeAndShareCard,
|
||||
/***
|
||||
* <a href=
|
||||
* "http://mp.weixin.qq.com/wiki/11/74ad127cc054f6b80759c40f77ec03db.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"
|
||||
* >微信支付-发起一个微信支付请求</a>
|
||||
*/
|
||||
chooseWXPay;
|
||||
|
||||
/**
|
||||
* 分享接口集合
|
||||
*/
|
||||
public final static JSSDKAPI[] SHARE_APIS = { onMenuShareTimeline,
|
||||
onMenuShareAppMessage, onMenuShareQQ, onMenuShareWeibo,
|
||||
onMenuShareQZone };
|
||||
/**
|
||||
* 图像接口集合
|
||||
*/
|
||||
public final static JSSDKAPI[] IMAGE_APIS = { chooseImage, previewImage,
|
||||
uploadImage, downloadImage };
|
||||
/**
|
||||
* 音频接口集合
|
||||
*/
|
||||
public final static JSSDKAPI[] RECORD_APIS = { startRecord, stopRecord,
|
||||
onVoiceRecordEnd, playVoice, pauseVoice, stopVoice, onVoicePlayEnd,
|
||||
uploadVoice, downloadVoice };
|
||||
/**
|
||||
* 智能接口集合
|
||||
*/
|
||||
public final static JSSDKAPI[] SEM_APIS = { translateVoice };
|
||||
/**
|
||||
* 设备信息接口集合
|
||||
*/
|
||||
public final static JSSDKAPI[] DEVICE_APIS = { getNetworkType };
|
||||
/**
|
||||
* 地理位置接口集合
|
||||
*/
|
||||
public final static JSSDKAPI[] LOCATION_APIS = { openLocation, getLocation };
|
||||
/**
|
||||
* 摇一摇周边接口集合
|
||||
*/
|
||||
public final static JSSDKAPI[] BEACON_APIS = { startSearchBeacons,
|
||||
stopSearchBeacons, onSearchBeacons };
|
||||
/**
|
||||
* 界面操作接口集合
|
||||
*/
|
||||
public final static JSSDKAPI[] UI_APIS = { hideOptionMenu, showOptionMenu,
|
||||
closeWindow, hideMenuItems, showMenuItems, hideAllNonBaseMenuItem,
|
||||
showAllNonBaseMenuItem };
|
||||
/**
|
||||
* 微信扫一扫接口集合
|
||||
*/
|
||||
public final static JSSDKAPI[] SCAN_APIS = { scanQRCode };
|
||||
/**
|
||||
* 微信小店接口集合
|
||||
*/
|
||||
public final static JSSDKAPI[] SHOP_APIS = { openProductSpecificView };
|
||||
/**
|
||||
* 微信卡券接口集合
|
||||
*/
|
||||
public final static JSSDKAPI[] CARD_APIS = { chooseCard, addCard, openCard,
|
||||
consumeAndShareCard };
|
||||
/**
|
||||
* 微信支付接口集合
|
||||
*/
|
||||
public final static JSSDKAPI[] PAY_APIS = { chooseWXPay };
|
||||
}
|
||||
@ -0,0 +1,124 @@
|
||||
package com.foxinmy.weixin4j.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
|
||||
/**
|
||||
* JSSDK帮助类
|
||||
*
|
||||
* @className JSSDKHelper
|
||||
* @author jy
|
||||
* @date 2015年12月23日
|
||||
* @since JDK 1.6
|
||||
* @see
|
||||
*/
|
||||
public class JSSDKHelper {
|
||||
private final TokenHolder ticketTokenHolder;
|
||||
private JSONObject config;
|
||||
private Set<JSSDKAPI> apis;
|
||||
|
||||
/**
|
||||
* ticket保存类 可调用WeixinProxy#getJSTicketHolder获取
|
||||
*
|
||||
* @param ticketTokenHolder
|
||||
*/
|
||||
public JSSDKHelper(TokenHolder ticketTokenHolder) {
|
||||
this.ticketTokenHolder = ticketTokenHolder;
|
||||
this.config = new JSONObject();
|
||||
this.apis = new HashSet<JSSDKAPI>();
|
||||
}
|
||||
|
||||
/**
|
||||
* 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,
|
||||
* 仅在pc端时才会打印。
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public JSSDKHelper debugMode() {
|
||||
config.put("debug", true);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 公众号的唯一标识 不填则获取weixin4j.properties#account中的id
|
||||
*
|
||||
* @param appId
|
||||
* @return
|
||||
*/
|
||||
public JSSDKHelper appId(String appId) {
|
||||
config.put("appId", appId);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 需要使用的JS接口列表
|
||||
*
|
||||
* @see JSSDKAPI
|
||||
* @param apis
|
||||
* @return
|
||||
*/
|
||||
public JSSDKHelper apis(JSSDKAPI... apis) {
|
||||
for (JSSDKAPI api : apis) {
|
||||
this.apis.add(api);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 需要使用的JS接口列表
|
||||
*
|
||||
* @see JSSDKAPI
|
||||
* @param apis
|
||||
* @return
|
||||
*/
|
||||
public JSSDKHelper apis(JSSDKAPI[]... apis) {
|
||||
for (JSSDKAPI[] api : apis) {
|
||||
for (JSSDKAPI apii : api) {
|
||||
this.apis.add(apii);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成config字符串
|
||||
*
|
||||
* @param url
|
||||
* 当前网页的URL,不包含#及其后面部分
|
||||
* @return
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/11/74ad127cc054f6b80759c40f77ec03db.html#.E6.AD.A5.E9.AA.A4.E4.B8.89.EF.BC.9A.E9.80.9A.E8.BF.87config.E6.8E.A5.E5.8F.A3.E6.B3.A8.E5.85.A5.E6.9D.83.E9.99.90.E9.AA.8C.E8.AF.81.E9.85.8D.E7.BD.AE">通过config接口注入权限验证配置</a>
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public String toJSONConfig(String url) throws WeixinException {
|
||||
Map<String, String> signMap = new HashMap<String, String>();
|
||||
String timestamp = DateUtil.timestamp2string();
|
||||
String noncestr = RandomUtil.generateString(24);
|
||||
signMap.put("timestamp", timestamp);
|
||||
signMap.put("noncestr", noncestr);
|
||||
signMap.put("jsapi_ticket", this.ticketTokenHolder.getAccessToken());
|
||||
signMap.put("url", url);
|
||||
String sign = DigestUtil.SHA1(MapUtil
|
||||
.toJoinString(signMap, false, true));
|
||||
if (StringUtil.isBlank(config.getString("appId"))) {
|
||||
config.put("appId", Weixin4jConfigUtil.getWeixinAccount().getId());
|
||||
}
|
||||
if (StringUtil.isBlank(config.getString("debug"))) {
|
||||
config.put("debug", false);
|
||||
}
|
||||
if (apis.isEmpty()) {
|
||||
throw new WeixinException("jsapilist not be empty");
|
||||
}
|
||||
config.put("timestamp", timestamp);
|
||||
config.put("noncestr", noncestr);
|
||||
config.put("signature", sign);
|
||||
config.put("jsApiList", apis.toArray());
|
||||
return config.toJSONString();
|
||||
}
|
||||
}
|
||||
@ -42,6 +42,7 @@ import com.foxinmy.weixin4j.mp.model.QRResult;
|
||||
import com.foxinmy.weixin4j.mp.model.SemQuery;
|
||||
import com.foxinmy.weixin4j.mp.model.SemResult;
|
||||
import com.foxinmy.weixin4j.mp.model.User;
|
||||
import com.foxinmy.weixin4j.mp.token.WeixinJSTicketCreator;
|
||||
import com.foxinmy.weixin4j.mp.token.WeixinTokenCreator;
|
||||
import com.foxinmy.weixin4j.mp.type.DatacubeType;
|
||||
import com.foxinmy.weixin4j.mp.type.IndustryType;
|
||||
@ -78,6 +79,7 @@ public class WeixinProxy {
|
||||
private final DataApi dataApi;
|
||||
|
||||
private final TokenHolder tokenHolder;
|
||||
private String appId;
|
||||
|
||||
/**
|
||||
* 默认使用文件方式保存token、使用weixin4j.properties配置的账号信息
|
||||
@ -115,15 +117,16 @@ public class WeixinProxy {
|
||||
TokenStorager tokenStorager) {
|
||||
this(new TokenHolder(new WeixinTokenCreator(appid, appsecret),
|
||||
tokenStorager));
|
||||
this.appId = appid;
|
||||
}
|
||||
|
||||
/**
|
||||
* 注意:TokenCreator 需为 <font color="red">WeixinTokenCreator</font>
|
||||
*
|
||||
* @see com.foxinmy.weixin4j.mp.token.WeixinTokenCreator.WeixinTokenCreator
|
||||
* @see com.foxinmy.weixin4j.mp.token.WeixinTokenCreator
|
||||
* @param tokenHolder
|
||||
*/
|
||||
public WeixinProxy(TokenHolder tokenHolder) {
|
||||
private WeixinProxy(TokenHolder tokenHolder) {
|
||||
this.tokenHolder = tokenHolder;
|
||||
this.mediaApi = new MediaApi(tokenHolder);
|
||||
this.notifyApi = new NotifyApi(tokenHolder);
|
||||
@ -138,10 +141,34 @@ public class WeixinProxy {
|
||||
this.dataApi = new DataApi(tokenHolder);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取appid
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getAppId() {
|
||||
return this.appId;
|
||||
}
|
||||
|
||||
/**
|
||||
* token获取
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public TokenHolder getTokenHolder() {
|
||||
return this.tokenHolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取JSSDK的tokenHolder
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public TokenHolder getJSTicketHolder() {
|
||||
return new TokenHolder(new WeixinJSTicketCreator(this.appId,
|
||||
this.tokenHolder), this.tokenHolder.getTokenStorager());
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传图文消息内的图片获取URL
|
||||
* 请注意,本接口所上传的图片不占用公众号的素材库中图片数量的5000个的限制。图片仅支持jpg/png格式,大小必须在1MB以下。
|
||||
|
||||
@ -58,7 +58,7 @@ public class MenuApi extends MpApi {
|
||||
private JsonResult createMenu0(String url, JSONObject data)
|
||||
throws WeixinException {
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(url, "h5hb64iP9mBzt0rK6DW1OuOpE066F6iQXmHUqJ83fxTHkDaA0tNOjMMuUrWGwAves4Vi5bfwPKdp3IVhCsZCOHhsX74GXnrTtMg_oFPgiUwSXEhAIABGN"),
|
||||
String.format(url, tokenHolder.getAccessToken()),
|
||||
JSON.toJSONString(data, new NameFilter() {
|
||||
@Override
|
||||
public String process(Object object, String name,
|
||||
@ -129,8 +129,8 @@ public class MenuApi extends MpApi {
|
||||
for (int i = 0; i < menuObjs.size(); i++) {
|
||||
menuObj = menuObjs.getJSONObject(i);
|
||||
menus.add(new Menu(menuObj.getString("menuid"),
|
||||
buttonsConvertor(menuObj),
|
||||
menuObj.getObject("matchrule", MenuMatchRule.class)));
|
||||
buttonsConvertor(menuObj), menuObj.getObject(
|
||||
"matchrule", MenuMatchRule.class)));
|
||||
}
|
||||
}
|
||||
return menus;
|
||||
|
||||
@ -45,7 +45,11 @@ public class MenuTest extends TokenTest {
|
||||
Button button = new Button("小哥介绍", domain, ButtonType.view);
|
||||
button.pushSub(new Button(
|
||||
"小哥介绍",
|
||||
"http://mp.weixin.qq.com/s?__biz=MzI2MTA5OTM4OQ==&mid=400990970&idx=1&sn=5c7fd72e782c49f7c933b91c63eddc80#rd",
|
||||
"http://x.eqxiu.com/s/89oy462U",
|
||||
ButtonType.view));
|
||||
button.pushSub(new Button(
|
||||
"小哥官网",
|
||||
"http://www.jdxiaoge.com",
|
||||
ButtonType.view));
|
||||
button.pushSub(new Button("兴趣部落", "http://buluo.qq.com/p/barindex.html?from=share&bid=282651", ButtonType.view));
|
||||
button.pushSub(new Button("服务流程", "FLOW", ButtonType.click));
|
||||
|
||||
@ -39,6 +39,7 @@ import com.foxinmy.weixin4j.qy.model.IdParameter;
|
||||
import com.foxinmy.weixin4j.qy.model.Party;
|
||||
import com.foxinmy.weixin4j.qy.model.Tag;
|
||||
import com.foxinmy.weixin4j.qy.model.User;
|
||||
import com.foxinmy.weixin4j.qy.suite.WeixinTokenSuiteCreator;
|
||||
import com.foxinmy.weixin4j.qy.token.WeixinTokenCreator;
|
||||
import com.foxinmy.weixin4j.qy.type.ChatType;
|
||||
import com.foxinmy.weixin4j.qy.type.InviteType;
|
||||
@ -71,6 +72,7 @@ public class WeixinProxy {
|
||||
private final ChatApi chatApi;
|
||||
|
||||
private final TokenHolder tokenHolder;
|
||||
private String corpId;
|
||||
|
||||
/**
|
||||
* 默认使用文件方式保存token、使用weixin4j.properties配置的账号信息
|
||||
@ -113,6 +115,21 @@ public class WeixinProxy {
|
||||
TokenStorager tokenStorager) {
|
||||
this(new TokenHolder(new WeixinTokenCreator(corpid, corpsecret),
|
||||
tokenStorager));
|
||||
this.corpId = corpid;
|
||||
}
|
||||
|
||||
/**
|
||||
* 第三方套件(永久授权码机制)
|
||||
*
|
||||
* @param tokenCreator
|
||||
* 微信企业号token创建(永久授权码)
|
||||
* @param tokenStorager
|
||||
* token存储
|
||||
*/
|
||||
public WeixinProxy(WeixinTokenSuiteCreator tokenCreator,
|
||||
TokenStorager tokenStorager) {
|
||||
this(new TokenHolder(tokenCreator, tokenStorager));
|
||||
this.corpId = tokenCreator.getAuthCorpId();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -121,7 +138,7 @@ public class WeixinProxy {
|
||||
* @see com.foxinmy.weixin4j.qy.token.WeixinTokenCreator.WeixinTokenCreator
|
||||
* @param tokenHolder
|
||||
*/
|
||||
public WeixinProxy(TokenHolder tokenHolder) {
|
||||
private WeixinProxy(TokenHolder tokenHolder) {
|
||||
this.tokenHolder = tokenHolder;
|
||||
this.partyApi = new PartyApi(tokenHolder);
|
||||
this.userApi = new UserApi(tokenHolder);
|
||||
@ -135,10 +152,27 @@ public class WeixinProxy {
|
||||
this.chatApi = new ChatApi(tokenHolder);
|
||||
}
|
||||
|
||||
/**
|
||||
* token获取
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public TokenHolder getTokenHolder() {
|
||||
return this.tokenHolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取JSSDK的tokenHolder
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public TokenHolder getJSTicketHolder() {
|
||||
return new TokenHolder(
|
||||
new com.foxinmy.weixin4j.qy.token.WeixinJSTicketCreator(
|
||||
this.corpId, this.tokenHolder),
|
||||
this.tokenHolder.getTokenStorager());
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送客服消息(需要管理员对应用有使用权限,对收件人touser、toparty、totag有查看权限,否则本次调用失败)
|
||||
* <p>
|
||||
|
||||
@ -6,6 +6,7 @@ import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.http.weixin.JsonResult;
|
||||
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.qy.WeixinProxy;
|
||||
import com.foxinmy.weixin4j.qy.model.AgentInfo;
|
||||
import com.foxinmy.weixin4j.qy.model.AgentSetter;
|
||||
import com.foxinmy.weixin4j.qy.model.OUserInfo;
|
||||
@ -65,7 +66,7 @@ public class SuiteApi extends QyApi {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public TokenHolder getTokenHolder() {
|
||||
public TokenHolder getSuiteTokenHolder() {
|
||||
return this.suiteTokenHolder;
|
||||
}
|
||||
|
||||
@ -107,12 +108,25 @@ public class SuiteApi extends QyApi {
|
||||
* 授权方corpid
|
||||
* @return 企业号token
|
||||
*/
|
||||
public TokenHolder createTokenHolder(String authCorpId) {
|
||||
public TokenHolder getTokenSuiteHolder(String authCorpId) {
|
||||
return new TokenHolder(new WeixinTokenSuiteCreator(
|
||||
getPerCodeHolder(authCorpId), suiteTokenHolder),
|
||||
suiteTicketHolder.getTokenStorager());
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建WeixinProxy对象
|
||||
*
|
||||
* @param authCorpId
|
||||
* 已授权的corpid
|
||||
* @return
|
||||
*/
|
||||
public WeixinProxy getWeixinProxy(String authCorpId) {
|
||||
return new WeixinProxy(new WeixinTokenSuiteCreator(
|
||||
getPerCodeHolder(authCorpId), suiteTokenHolder),
|
||||
suiteTicketHolder.getTokenStorager());
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置套件授权配置:如果需要对某次授权进行配置,则调用本接口,目前仅可以设置哪些应用可以授权,不调用则默认允许所有应用进行授权。
|
||||
*
|
||||
|
||||
@ -63,4 +63,13 @@ public class WeixinTokenSuiteCreator implements TokenCreator {
|
||||
token.setTime(System.currentTimeMillis());
|
||||
return token;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取授权放的corpid
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getAuthCorpId() {
|
||||
return this.perCodeHolder.getAuthCorpId();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user