1、https://github.com/liyiorg/weixin-popular
weixin-popular
微信公衆平臺Java SDK
介紹
weixin-popular 包括微信公衆平臺基礎API與支付API,提供便捷的API調用接口.
API 列表
- TokenAPI access_token 獲取
- MediaAPI 多媒體上傳下載(臨時素材)
- MaterialAPI 永久素材
- MenuAPI 菜單
- MessageAPI 信息發送(客服消息、羣發消息、模板消息)
- PayAPI 支付訂單相關接口
- PayMchAPI 支付訂單相關接口(商戶平臺版)
- QrcodeAPI 二維碼
- SnsAPI 網籤授權
- UserAPI 用戶管理
- ShorturlAPI 長鏈接轉短鏈接
- TicketAPI JSAPI ticket
- ComponentAPI 第三方開發平臺
工具類
- PayUtil 支付工具類,生成JS支付,原生支付
- SignatureUtil 籤權生成、驗證
- XMLConverUtil XML 對象轉換(JAXB)
- JsUtil JsAPI config,chooseWXPay JSON生成
example
其它
參考資料
2、https://github.com/caijianqing/weixinmp4java
微信公衆平臺API接口JAVA版
- 別名:weixinmp4java、wechat4java
- 這個包是微信公衆平臺純API接口實現,除了一個gson的jar包以外,沒有任何業務代碼。
- 支持公衆號(包括訂閱號和服務號)的所有主動接口和被動接口。
- 支持小店接口v1.4
最近更新
2014.07.07
- 將代碼切換爲maven管理
- 原代碼保留在no_maven目錄中
2014.07.06 v91
- 小店API 1.4完成【警告:小店代碼僅在本地進行模擬測試,沒有經過微信服務器測試,歡迎有條件的同學反饋BUG】
- cjc.weixinmp包增加了7個以Merchant開頭的類,分別對應API手冊的7個功能接口,每個方法對應一個功能
- 增加cjc.weixinmp.merchant.bean包,存放與小店有關實體
- 增加cjc.weixinmp.merchant.builder包,因爲小店的數據實體比較複雜(很多字段很多結構),所有特設數據構造器,非常好用!
- AbstractUserOperate增加onMerchantOrderPayEvent接口,爲小店的訂單支付推送事件
- 詳細測試例子查看cjc.weixinmp.test.WeixinmpTestXiaodianServlet,部署test項目後打開首頁可以看到連接。
- 內建模擬測試服務器,是本屌在封裝小店接口時,因爲沒有小店測試權限特別開發的本地模擬測試模式。
- 開關在cjc.weixinmp.test.Engine的contextInitialized方法,默認關,見註釋。
項目介紹
/weixinmp 實現代碼主項目,可以輸出爲jar包使用。注意依賴gson.jar。
/weixinmp.test 示例&測試項目,看這裏快速上手。需要依賴/weixinmp項目,
注意不是把代碼複製過來用,而是在Eclipse或者MyEclipse是兩個project的形式。
軟件包介紹
cjc.weixinmp
包含事件分發、主動調用、通訊,解析json,解析xml,日誌儲存,讀取配置文件,讀取幫助文件信息等功能。
cjc.weixinmp.bean
接口通訊中涉及到的數據格式(xml或者json),已被封裝爲實體。
cjc.weixinmp.merchant.bean
存放與小店有關實體
cjc.weixinmp.merchant.builder
因爲小店的數據實體比較複雜(很多字段很多結構),所有特設數據構造器,非常好用!
配置文件
/weixinmp.default.properties
框架基本設置,請複製一份並重命名爲weixinmp.properties存放在你的src根目錄下。
- 公衆號的基本信息(token、appid、appsecret等)
- 公衆平臺API接口配置(各種URL)
- 代理設置(支持通過代理上網的環境)
/weixinmp_helps.xml
幫助信息文件,請複製一份weixinmp_helps.xml存放在你的src目錄下。
- 幫助信息配置文件,由controller.getHelp(key)獲得內容。
接口介紹
cjc.weixinmp.AbstractUserOperate
由微信服務器對你的服務器進行調用的接口稱之爲被動接口。 例如:發送文本消息、語音消息、訂閱事件、退訂事件、點擊菜單事件等。 該接口已包含了所有開放的接口,選擇需要的方法進行重寫,並編寫自己的業務代碼即可。
// 用戶主動發送文本消息事件
AbstractResponse cjc.weixinmp.AbstractUserOperate.onTextMessage(TextRequest text)
// 用戶主動發圖片消息事件
AbstractResponse cjc.weixinmp.AbstractUserOperate.onImageMessage(ImageRequest image)
// 用戶主動發語音消息事件
AbstractResponse cjc.weixinmp.AbstractUserOperate.onVoiceMessage(VoiceRequest voice)
// 用戶主動發視頻消息事件
AbstractResponse cjc.weixinmp.AbstractUserOperate.onVideoMessage(VideoRequest video)
// 用戶主動發位置消息事件
AbstractResponse cjc.weixinmp.AbstractUserOperate.onLocationMessage(LocationRequest location)
// 用戶主動發鏈接消息事件
AbstractResponse cjc.weixinmp.AbstractUserOperate.onLinkMessage(LinkRequest link)
// 用戶訂閱事件
AbstractResponse cjc.weixinmp.AbstractUserOperate.onSubscribeEvent(SubscribeEventRequest event)
// 用戶退訂事件
AbstractResponse cjc.weixinmp.AbstractUserOperate.onUnsubscribeEvent(SubscribeEventRequest event)
// 用戶掃描參數二維碼事件
AbstractResponse cjc.weixinmp.AbstractUserOperate.onScanEvent(ScanEventRequest event)
// 自動上報位置信息事件
AbstractResponse cjc.weixinmp.AbstractUserOperate.onLocationEvent(LocationEventRequest event)
// 用戶點擊自定義菜單事件
AbstractResponse cjc.weixinmp.AbstractUserOperate.onClickEvent(ClickEventRequest click)
// 小店支付通知
AbstractResponse cjc.weixinmp.AbstractUserOperate.onMerchantOrderPayEvent(OrderPayEventRequest orderPayEvent)
以“用戶訂閱事件”爲例:
AbstractResponse cjc.weixinmp.AbstractUserOperate.onSubscribeEvent(SubscribeEventRequest event){
// 從幫助信息文件(weixinmp_helps.xml)中加載。也可以自己new TextResponse對象。
String help = controller.findHelp("歡迎關注");
// 這個是內置的一個快速構建“文本回復”的方法,這裏意思是向用戶回覆“歡迎關注”的文字。
return buildTextResponse(help);
}
cjc.weixinmp.AbstractWeixinmpController
這個是API的總控制器,包含主動接口和被動接口。 這個控制器應該在Application上下文的生命週期內只創建一個實例,並接管某一個Servlet的doPost和doGet請求。
AbstractUserOperate cjc.weixinmp.test.WeixinmpController.getUserOperate(String FromUserName)
這個抽象方法爲每次用戶主動發送消息時調用,一般返回與用戶綁定的AbstractUserOperate對象,這樣保證用戶會話不被串線。
void cjc.weixinmp.test.WeixinmpController.logInfo(String msg)
這是框架默認的記錄日誌方法,你可以重寫它以及其他幾個日誌方法,用你自己的記錄方式,例如log4j。
主動接口
由你的服務器對微信服務器進行主動調用的接口稱之爲主動服務。 例如:自定義菜單、客戶消息用戶管理等。
以下爲可用的接口(注意:這些主動接口大部分爲高級接口,需要服務號才能使用):
// 自定義菜單接口
CustomerMenuService cjc.weixinmp.AbstractWeixinmpController.getCustomMenuService()
// 上傳下載接口
MediaLibraryService cjc.weixinmp.AbstractWeixinmpController.getMediaLibraryService()
// 客戶消息接口
MessageService cjc.weixinmp.AbstractWeixinmpController.getMessageService()
// 參數二維碼接口
QRCodeService cjc.weixinmp.AbstractWeixinmpController.getQrCodeService()
// 用戶管理接口
UserManagerService cjc.weixinmp.AbstractWeixinmpController.getUserManagerService()
// 商品管理接口
MerchantProductService cjc.weixinmp.AbstractWeixinmpController.getMerchantProductService();
// 庫存管理接口
MerchantStockService cjc.weixinmp.AbstractWeixinmpController.getMerchantStockService();
// 郵費模板管理接口
MerchantExpressService cjc.weixinmp.AbstractWeixinmpController.getMerchantExpressService();
// 商品分組管理接口
MerchantGroupService cjc.weixinmp.AbstractWeixinmpController.getMerchantGroupService();
// 貨架管理接口
MerchantShelfService cjc.weixinmp.AbstractWeixinmpController.getMerchantShelfService();
// 訂單管理接口
MerchantOrderService cjc.weixinmp.AbstractWeixinmpController.getMerchantOrderService();
以創建自定義菜單爲例:
CustomButton button = new CustomButton();
button.addButton(CustomMenu.TYPE.click, "空按鈕", "anniu1", null);
button.addButton(CustomMenu.TYPE.view, "百度", null, "http://www.baidu.com");
button.addButton(CustomMenu.TYPE.click, "菜單", "anniu1", null) //
.addSubButton(CustomMenu.TYPE.click, "按鈕一", "anniu1", null) //
.addSubButton(CustomMenu.TYPE.click, "按鈕二", "anniu2", null) //
.addSubButton(CustomMenu.TYPE.view, "視頻", null, "http://v.qq.com");
AbstractWeixinmpController.getCustomMenuService().updateMenu(button);
3、https://github.com/foxinmy/weixin4j
weixin4j
微信開發工具包
功能列表
-
weixin4j-mp
公衆平臺API封裝
微信支付(刷卡/掃碼/公衆號)
-
weixin4j-qy
企業號API封裝
-
weixin4j-server
netty服務器&消息分發
項目說明
-
weixin4j
包含「微信公衆平臺」和「微信企業號」的API封裝. -
API的成功調用依賴於正確的appid等數據,填寫格式說明見API工程下的README.md文件.
-
netty服務正在重構中
如何獲取
1.maven依賴(1.4,2015-04-29 released)
微信公衆平臺API
<dependency>
<groupId>com.foxinmy</groupId>
<artifactId>weixin4j-mp</artifactId>
<version>1.4</version>
</dependency>
微信企業號API
<dependency>
<groupId>com.foxinmy</groupId>
<artifactId>weixin4j-qy</artifactId>
<version>1.4</version>
</dependency>
微信被動消息服務器
正在重構中..
以上依賴如果出現Missing artifact錯誤 請嘗試在eclipse裏這麼做
-
進入 Window > Show View > Other > Maven Repositories 展開 Global Repositories 在group或者central上右鍵執行
update index
操作 -
或者進入 Windows > Preferences > Maven 選中
Download repository index updates on startup
即可
2.直接下載jar包
https://github.com/foxinmy/weixin4j/releases
3.從源碼打包
git clone
&mvn
package -Prelease
更新LOG
接下來
- 被動消息服務重構
-
公衆號第三方服務應用
-
企業號第三方應用 & 企業號登陸授權
-
硬件設備 & 搖一搖周邊
-
微信小店
-
微信卡券
微信公衆號、企業號Java SDK。
詳細文檔請看 wiki。
Quick Start
如果要開發公衆號(訂閱號、服務號)應用,在你的maven項目中添加:
<dependency>
<groupId>me.chanjar</groupId>
<artifactId>weixin-java-mp</artifactId>
<version>1.1.4</version>
</dependency>
如果要開發企業號應用,在你的maven項目中添加:
<dependency>
<groupId>me.chanjar</groupId>
<artifactId>weixin-java-cp</artifactId>
<version>1.1.4</version>
</dependency>
SNAPSHOT版
本項目的BUG修復和新特性一般會先發布在-SNAPSHOT版裏供大家預覽,如果要使用-SNAPSHOT版,則需要在你的pom.xml中添加這段:
<repositories>
<repository>
<snapshots />
<id>sonatype snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</repository>
</repositories>