parent
762a921ecc
commit
5c23b5d88d
@ -0,0 +1,11 @@
|
|||||||
|
package com.example.demo.weixin.bean.menu;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class AccessToken {
|
||||||
|
private String Access_token;
|
||||||
|
private int Expires_in;
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package com.example.demo.weixin.bean.menu;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 菜单
|
||||||
|
* @Parameters:
|
||||||
|
* @Return:
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
|
public class Menu {
|
||||||
|
private Button[] button;
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package com.example.demo.weixin.bean.menu;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: view类型的按钮(有type、name、url三个属性)
|
||||||
|
* @Parameters:
|
||||||
|
* @Return:
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class ViewButton extends Button {
|
||||||
|
public String type;
|
||||||
|
public String url;
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package com.example.demo.weixin.bean.message;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
|
public class Image {
|
||||||
|
//媒体文件ID
|
||||||
|
private String MediaId;
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package com.example.demo.weixin.bean.message;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
|
public class Video {
|
||||||
|
//媒体文件ID
|
||||||
|
private String MediaId;
|
||||||
|
//视频消息缩略图的媒体ID
|
||||||
|
private String ThumbMediaId;
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package com.example.demo.weixin.bean.message;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
|
public class Voice {
|
||||||
|
//语音消息媒体ID
|
||||||
|
private String mediaId;
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package com.example.demo.weixin.bean.response;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
|
public class BaseMessage {
|
||||||
|
//接收方账号(收到的OpenID)
|
||||||
|
private String ToUserName;
|
||||||
|
//开发者微信号
|
||||||
|
private String FromUserName;
|
||||||
|
//消息创建时间(整型)
|
||||||
|
private long CreateTime;
|
||||||
|
//消息类型(text/music/news)
|
||||||
|
private String MsgType;
|
||||||
|
//星标刚收到的消息
|
||||||
|
private int FuncFlag;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package com.example.demo.weixin.bean.response;
|
||||||
|
|
||||||
|
|
||||||
|
import com.example.demo.weixin.bean.message.Image;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class ImageMessage extends BaseMessage {
|
||||||
|
private Image image;
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package com.example.demo.weixin.bean.response;
|
||||||
|
|
||||||
|
import com.example.demo.weixin.bean.message.Music;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class MusicMessage extends BaseMessage {
|
||||||
|
private Music music;
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package com.example.demo.weixin.bean.response;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class TextMessage extends BaseMessage {
|
||||||
|
//回复的消息内容
|
||||||
|
private String Content;
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package com.example.demo.weixin.bean.response;
|
||||||
|
|
||||||
|
import com.example.demo.weixin.bean.message.Video;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class VideoMessage extends BaseMessage {
|
||||||
|
private Video video;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package com.example.demo.weixin.bean.response;
|
||||||
|
|
||||||
|
import com.example.demo.weixin.bean.message.Voice;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class VoiceMessage extends BaseMessage{
|
||||||
|
private Voice voice;
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package com.example.demo.weixin.service;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class DataProcess {
|
||||||
|
public boolean dataIsNull(String respXml){
|
||||||
|
if(respXml.isEmpty()){
|
||||||
|
return true;
|
||||||
|
}else{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
package com.example.demo.weixin.service;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
public interface WeixinCoreService {
|
||||||
|
public abstract String weixinMessageHandelCoreService(HttpServletRequest request,HttpServletResponse response);
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
package com.example.demo.weixin.util.menu;
|
||||||
|
|
||||||
|
public class WechatConstants {
|
||||||
|
public static String ACCESS_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET";
|
||||||
|
public static String MENU_CREATE_URL = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN";
|
||||||
|
public static String MENU_GET_URL = "https://api.weixin.qq.com/cgi-bin/menu/get?access_token=ACCESS_TOKEN";
|
||||||
|
public static String MENU_DELETE_URL = "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=ACCESS_TOKEN";
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
package com.example.demo.weixin.util.menu;
|
||||||
|
|
||||||
|
|
||||||
|
import com.example.demo.weixin.bean.menu.Menu;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 创建自定义菜单主方法
|
||||||
|
* @Parameters:
|
||||||
|
* @Return:
|
||||||
|
*/
|
||||||
|
public class WechatCreatDefaultMenu {
|
||||||
|
public static void main(String[] args){
|
||||||
|
WechatCommonUtil wechatCommonUtil = new WechatCommonUtil();
|
||||||
|
WechatMenuUtil wechatMenuUtil = new WechatMenuUtil();
|
||||||
|
WechatMenuManagerUtil wechatMenuManagerUtil = new WechatMenuManagerUtil();
|
||||||
|
String appid = "wx473235c6be5c945a";
|
||||||
|
String appsecret = "69a0c7bcccf20833fd549ae9a530d299";
|
||||||
|
|
||||||
|
//获取access_token
|
||||||
|
String accessToken = wechatCommonUtil.getAccessToken(appid, appsecret).getAccess_token();
|
||||||
|
//获取菜单结构
|
||||||
|
Menu menu = wechatMenuManagerUtil.getMenu();
|
||||||
|
if (accessToken!=null) {
|
||||||
|
//生成菜单
|
||||||
|
boolean result = wechatMenuUtil.creatMenu(menu, accessToken);
|
||||||
|
if (result) {
|
||||||
|
System.out.println("菜单创建成功");
|
||||||
|
}else {
|
||||||
|
System.out.println("菜单创建失败");
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
System.out.println("token为空");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
package com.example.demo.weixin.util.menu;
|
||||||
|
|
||||||
|
import com.example.demo.weixin.bean.menu.*;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 菜单管理器类
|
||||||
|
* @Parameters:
|
||||||
|
* @Return:
|
||||||
|
*/
|
||||||
|
public class WechatMenuManagerUtil {
|
||||||
|
/**
|
||||||
|
* @Description: 定义菜单结构
|
||||||
|
* @Parameters:
|
||||||
|
* @Return:
|
||||||
|
*/
|
||||||
|
public Menu getMenu(){
|
||||||
|
// ClickButton firstClickButton = new ClickButton();
|
||||||
|
// firstClickButton.setName("功能图文");
|
||||||
|
// firstClickButton.setKey("function");
|
||||||
|
// firstClickButton.setType("click");
|
||||||
|
|
||||||
|
ViewButton firstViewButton = new ViewButton();
|
||||||
|
firstViewButton.setName("业务介绍");
|
||||||
|
firstViewButton.setType("view");
|
||||||
|
firstViewButton.setUrl("http://loan.ngrok.xiaomiqiu.cn/personalCenter.html");
|
||||||
|
|
||||||
|
ViewButton secondViewButton = new ViewButton();
|
||||||
|
secondViewButton.setName("我要贷款");
|
||||||
|
secondViewButton.setType("view");
|
||||||
|
secondViewButton.setUrl("http://loan.ngrok.xiaomiqiu.cn/personalCenter.html");
|
||||||
|
|
||||||
|
ComplexButton complexButton = new ComplexButton();
|
||||||
|
|
||||||
|
ViewButton viewButton1 = new ViewButton();
|
||||||
|
viewButton1.setType("view");
|
||||||
|
viewButton1.setName("个人中心");
|
||||||
|
viewButton1.setUrl("http://loan.ngrok.xiaomiqiu.cn/personalCenter.html");
|
||||||
|
|
||||||
|
ViewButton viewButton2 = new ViewButton();
|
||||||
|
viewButton2.setType("view");
|
||||||
|
viewButton2.setName("网页授权");
|
||||||
|
viewButton2.setUrl("http://loan.ngrok.xiaomiqiu.cn/personalCenter.html"); //http://loan.ngrok.xiaomiqiu.cn/WeChat/login.php
|
||||||
|
ViewButton[] viewButton = {viewButton1,viewButton2};
|
||||||
|
complexButton.setSub_button(viewButton);
|
||||||
|
complexButton.setName("我的服务");
|
||||||
|
|
||||||
|
Menu menu = new Menu();
|
||||||
|
Button[] boButtons = {firstViewButton,secondViewButton,complexButton};
|
||||||
|
menu.setButton(boButtons);
|
||||||
|
|
||||||
|
return menu;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in new issue