Browse Source

bug修改

chenyongxing 8 years ago
parent
commit
34eba07984

+ 15 - 4
common/common-rest-model/src/main/java/com/yihu/jw/restmodel/wx/WxContants.java

@ -28,17 +28,27 @@ public class WxContants {
        public static final String message_fail_code_is_null="code is null";
        public static final String message_fail_name_is_null="name is null";
        public static final String message_fail_type_is_null="type is null";
        public static final String message_fail_wxMenuKey_is_null="key is null";
        public static final String message_fail_wxMenuKey_is_toLong="key is toLong";
        public static final String message_fail_key_is_null="key is null";
        public static final String message_fail_key_is_toLong="key is to long";
        public static final String message_fail_url_is_null="url is null";
        public static final String message_fail_appid_is_null="appid is null";
        public static final String message_fail_pagepath_is_null="pagepath is null";
        public static final String message_fail_url_is_toLong="url is to long";
        public static final String message_fail_sort_is_null="sort is null";
        public static final String message_fail_sort_is_repeat="sort is repeat";
        public static final String message_fail_code_no_exist="code no exist";
        public static final String message_fail_supMenuCode_is_no_exist="supMenuCode is no exist";
        public static final String message_fail_mediaId_is_null="mediaId is null";
        public static final String message_fail_childMenu_is_to_much="childMenu is to much";//子菜单数目过多
        public static final String message_fail_parentMenu_is_to_much="parentMenu is to much";//子菜单数目过多
        public static final String message_fail_name_is_to_long="name is to long";
        public static final String message_success_update="wxMenu update success";
        public static final String message_success_delete="wxMenu delete success";
        public static final String message_success_find="wxMenu find success";
        public static final String message_success_create="wxMenu create success";
        public static final String message_success_find_functions="wxMenu find success";
    }
    //微信模板消息
    public static class WxTemplate {
@ -58,7 +68,6 @@ public class WxContants {
        public static final String message_success_delete="wxTemplate delete success";
        public static final String message_fail_code_is_null="code is null";
        public static final String message_fail_id_is_null="id is null";
        public static final String message_fail_code_no_exist="code no exist";
        public static final String message_fail_wechatCode_is_null="wechatCode is null";
        public static final String message_fail_templateid_is_null="templateid is null";
@ -87,6 +96,8 @@ public class WxContants {
        public static final String message_fail_appId_exist="wechat appId exist";
        public static final String message_fail_status_is_null="status is null";
        public static final String message_fail_type_is_null="type is null";
        public static final String message_fail_appId_is_null="appId is null";
        public static final String message_fail_name_is_null="name is null";
    }
    //微信图文消息
    public static class WxGraphicMessage {
@ -109,6 +120,6 @@ public class WxContants {
        public static final String message_fail_code_no_exist="code no exist";
        public static final String message_fail_code_exist="code exist";
        public static final String message_fail_status_is_null="status is null";
        public static final String message_fail_title_is_null="title is null";
    }
}

+ 7 - 6
svr/svr-base/src/main/java/com/yihu/jw/wx/controller/WxGraphicMessageController.java

@ -86,11 +86,11 @@ public class WxGraphicMessageController extends EnvelopRestController {
    @RequestMapping(value = WxContants.WxGraphicMessage.api_getWxGraphicMessages, method = RequestMethod.GET)
    @ApiOperation(value = "获取微信图文消息列表(分页)")
    public Envelop getWxGraphicMessages(
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段", defaultValue = "id,code,name,wechatCode,value,keyword,remark,status")
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段", defaultValue = "id,code,title,description,url,pic_url,remark,status")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "+name,+createTime")
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "+title,+createTime")
            @RequestParam(value = "sorts", required = false) String sorts,
            @ApiParam(name = "size", value = "分页大小", defaultValue = "15")
            @RequestParam(value = "size", required = false) int size,
@ -114,11 +114,11 @@ public class WxGraphicMessageController extends EnvelopRestController {
    @GetMapping(value = WxContants.WxGraphicMessage.api_getWxGraphicMessageNoPage)
    @ApiOperation(value = "获取图文消息列表,不分页")
    public Envelop getWxGraphicMessageNoPage(
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段", defaultValue = "id,code,name,wechatCode,value,keyword,remark,status")
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段", defaultValue = "id,code,title,description,url,pic_url,remark,status")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "+name,+createTime")
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "+title,+createTime")
            @RequestParam(value = "sorts", required = false) String sorts) throws Exception {
        //得到list数据
        List<WxGraphicMessage> list = wxGraphicMessageService.search(fields,filters,sorts);
@ -138,7 +138,8 @@ public class WxGraphicMessageController extends EnvelopRestController {
    @GetMapping(value = WxContants.WxGraphicMessage.api_sendGraphicMessages)
    @ApiOperation(value = "发送图文消息")
    public Envelop sendGraphicMessages(
    @ResponseBody
    public String sendGraphicMessages(
            @ApiParam(name = "codes", value = "根据code发送微信图文消息,多个code用,分割")
            @RequestParam(value = "codes", required = true) String codes,
            @ApiParam(name = "fromUserName", value = "用户openid")
@ -147,7 +148,7 @@ public class WxGraphicMessageController extends EnvelopRestController {
            @RequestParam(value = "toUserName", required = true) String toUserName
            ) throws Exception {
        String messages = wxGraphicMessageService.sendGraphicMessages(codes, fromUserName,toUserName);
        return Envelop.getSuccess("成功",messages);
        return messages;
    }

+ 3 - 4
svr/svr-base/src/main/java/com/yihu/jw/wx/controller/WxMenuController.java

@ -136,19 +136,18 @@ public class WxMenuController extends EnvelopRestController {
     */
    @ApiOperation(value = "创建微信公众号菜单", notes = "创建微信公众号菜单")
    @RequestMapping(value = WxContants.WxMenu.api_createMenu ,method = RequestMethod.GET)
    @ResponseBody
    public Envelop createWechatMenu(
            @ApiParam(name = "wechatCode", value = "", defaultValue = "")
            @RequestParam(value = "wechatCode", required = true)String wechatCode){
        try{
            JSONObject result = wxMenuService.createWechatMenu(wechatCode);
            if(result != null && result.get("errcode").toString().equals("0") && result.getString("errmsg").equals("ok")){
                return Envelop.getSuccess("创建成功",result );
                return Envelop.getSuccess("创建成功",result.toString() );
            }else{
                return Envelop.getSuccess("创建失败",result );
                return Envelop.getSuccess("创建失败",result.toString() );
            }
        }catch (Exception e){
            return Envelop.getSuccess("创建成功",e );
            return Envelop.getSuccess("创建失败",e );
        }
    }

+ 7 - 6
svr/svr-base/src/main/java/com/yihu/jw/wx/controller/WxTemplateController.java

@ -88,11 +88,11 @@ public class WxTemplateController extends EnvelopRestController {
    @RequestMapping(value = WxContants.WxTemplate.api_getWxTemplates, method = RequestMethod.GET)
    @ApiOperation(value = "获取微信模版列表(分页)")
    public Envelop getWechats(
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段", defaultValue = "id,code,name,saasId,appId,appSecret,baseUrl,remark")
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段", defaultValue = "id,code,title,wechatCode,templateId,content,remark,status")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "+name,+createTime")
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "+title,+createTime")
            @RequestParam(value = "sorts", required = false) String sorts,
            @ApiParam(name = "size", value = "分页大小", defaultValue = "15")
            @RequestParam(value = "size", required = false) int size,
@ -116,11 +116,11 @@ public class WxTemplateController extends EnvelopRestController {
    @GetMapping(value = WxContants.WxTemplate.api_getWxTemplatesNoPage)
    @ApiOperation(value = "获取微信模版列表(不分页)")
    public Envelop getWechatNoPage(
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段", defaultValue = "id,code,name,saasId,appId,appSecret,baseUrl,remark")
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段", defaultValue = "id,code,title,wechatCode,templateId,content,remark,status")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "+name,+createTime")
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "+title,+createTime")
            @RequestParam(value = "sorts", required = false) String sorts) throws Exception {
        //得到list数据
        List<WxTemplate> list = wxTemplateService.search(fields,filters,sorts);
@ -131,10 +131,11 @@ public class WxTemplateController extends EnvelopRestController {
    @GetMapping(value = WxContants.WxTemplate.api_sendTemplateMessage)
    @ApiOperation(value = "发送微信模板消息")
    @ResponseBody
    public Envelop sendTemplateMessage(
            @ApiParam(name="openid",value="微信用户的openid")
            @RequestParam String openid,
            @ApiParam(name="tempalteCode",value = "模板code")
            @ApiParam(name="templateCode",value = "模板code")
            @RequestParam String templateCode,
            @ApiParam(name="url",value="模板跳转链接")
            @RequestParam(required = false) String url,
@ -152,6 +153,6 @@ public class WxTemplateController extends EnvelopRestController {
            miniprogram.setPagepath(pagepath);
        }
        JSONObject jsonObject = wxTemplateService.sendTemplateMessage(openid, templateCode, url, data, miniprogram);
        return Envelop.getSuccess("成功",jsonObject);
        return Envelop.getSuccess("成功",jsonObject.toString());
    }
}

+ 2 - 0
svr/svr-base/src/main/java/com/yihu/jw/wx/dao/WxMenuDao.java

@ -37,4 +37,6 @@ public interface WxMenuDao  extends PagingAndSortingRepository<WxMenu, Long>, Jp
    @Query("from WxMenu m where m.wechatCode = ?1 and m.status =1 and m.sort =?2 and m.supMenucode =?3 and m.code != ?4")
    WxMenu findByWechatCodeExcludeSortFromChild(String wechatCode, Integer sort,String supMenucode,String code);
    @Query("from WxMenu m where m.wechatCode =?1 and m.status = 1 and m.supMenucode is null order by m.supMenucode ,m.sort")
    List<WxMenu> findParentMenuByWechatCode(String wechatCode);
}

+ 15 - 12
svr/svr-base/src/main/java/com/yihu/jw/wx/model/WxMenu.java

@ -18,7 +18,7 @@ public class WxMenu extends IdEntity implements java.io.Serializable {
    private String supMenucode;//父菜单id 如果是一级菜单 此字段为空
    private String type;//菜单类型
    private String name;//菜单名称
    private String key;//click等点击类型必须
    private String menuKey;//click等点击类型必须
    private Integer sort;//菜单排序 父菜单排序 不包含子菜单那
    private String url;//url
    private String mediaId;//点用新增永久素材接口返回的合法media_id
@ -32,13 +32,20 @@ public class WxMenu extends IdEntity implements java.io.Serializable {
    private Integer status; //状态 -1删除 0 冻结 1可用
    public WxMenu(String code, String wechatCode, String supMenucode, String type, String name, String key, Integer sort, String url, String mediaId, String appid, String pagepath, String updateUser, Date updateTime, Date createTime, String createUser, String remark, Integer status) {
    /**
     * default constructor
     */
    public WxMenu() {
    }
    public WxMenu(String code, String wechatCode, String supMenucode, String type, String name, String menuKey, Integer sort, String url, String mediaId, String appid, String pagepath, String updateUser, Date updateTime, Date createTime, String createUser, String remark, Integer status) {
        this.code = code;
        this.wechatCode = wechatCode;
        this.supMenucode = supMenucode;
        this.type = type;
        this.name = name;
        this.key = key;
        this.menuKey = menuKey;
        this.sort = sort;
        this.url = url;
        this.mediaId = mediaId;
@ -52,18 +59,14 @@ public class WxMenu extends IdEntity implements java.io.Serializable {
        this.status = status;
    }
    /**
     * default constructor
     */
    public WxMenu() {
    }
    @Column(name="menu_key")
    public String getKey() {
        return key;
    public String getMenuKey() {
        return menuKey;
    }
    public void setKey(String key) {
        this.key = key;
    public void setMenuKey(String menuKey) {
        this.menuKey = menuKey;
    }
    public String getMediaId() {

+ 10 - 4
svr/svr-base/src/main/java/com/yihu/jw/wx/service/WechatService.java

@ -32,8 +32,11 @@ public class WechatService extends BaseJpaService<WxWechat, WechatDao> {
        if (StringUtils.isEmpty(wechat.getType())) {
            throw new ApiException(WxContants.Wechat.message_fail_type_is_null, CommonContants.common_error_params_code);
        }
        if (StringUtils.isEmpty(wechat.getAppSecret())) {
            throw new ApiException(WxContants.Wechat.message_fail_appSecret_is_null, CommonContants.common_error_params_code);
        if (StringUtils.isEmpty(wechat.getName())) {
            throw new ApiException(WxContants.Wechat.message_fail_name_is_null, CommonContants.common_error_params_code);
        }
        if (StringUtils.isEmpty(wechat.getAppId())) {
            throw new ApiException(WxContants.Wechat.message_fail_appId_is_null, CommonContants.common_error_params_code);
        }
        if (StringUtils.isEmpty(wechat.getAppSecret())) {
            throw new ApiException(WxContants.Wechat.message_fail_appSecret_is_null, CommonContants.common_error_params_code);
@ -56,8 +59,11 @@ public class WechatService extends BaseJpaService<WxWechat, WechatDao> {
        if (StringUtils.isEmpty(wechat.getType())) {
            throw new ApiException(WxContants.Wechat.message_fail_type_is_null, CommonContants.common_error_params_code);
        }
        if (StringUtils.isEmpty(wechat.getAppSecret())) {
            throw new ApiException(WxContants.Wechat.message_fail_appSecret_is_null, CommonContants.common_error_params_code);
        if (StringUtils.isEmpty(wechat.getName())) {
            throw new ApiException(WxContants.Wechat.message_fail_name_is_null, CommonContants.common_error_params_code);
        }
        if (StringUtils.isEmpty(wechat.getAppId())) {
            throw new ApiException(WxContants.Wechat.message_fail_appId_is_null, CommonContants.common_error_params_code);
        }
        if (StringUtils.isEmpty(wechat.getAppSecret())) {
            throw new ApiException(WxContants.Wechat.message_fail_appSecret_is_null, CommonContants.common_error_params_code);

+ 5 - 1
svr/svr-base/src/main/java/com/yihu/jw/wx/service/WxGraphicMessageService.java

@ -32,6 +32,9 @@ public class WxGraphicMessageService extends BaseJpaService<WxGraphicMessage, Wx
        if (StringUtils.isEmpty(wxGraphicMessage.getStatus())) {
            throw new ApiException(WxContants.WxGraphicMessage.message_fail_status_is_null, CommonContants.common_error_params_code);
        }
        if (StringUtils.isEmpty(wxGraphicMessage.getTitle())) {
            throw new ApiException(WxContants.WxGraphicMessage.message_fail_title_is_null, CommonContants.common_error_params_code);
        }
        WxGraphicMessage wxGraphicMessageTem = wxGraphicMessageDao.findByCode(wxGraphicMessage.getCode());
        if (wxGraphicMessageTem != null) {
            throw new ApiException(WxContants.WxGraphicMessage.message_fail_code_exist, CommonContants.common_error_params_code);
@ -108,9 +111,10 @@ public class WxGraphicMessageService extends BaseJpaService<WxGraphicMessage, Wx
            Map<String, String> requestMap = MessageUtil.parseXml(request);
            //用户openid
            String fromUserName = requestMap.get("FromUserName");
            System.out.println("fromUserName+=   "+fromUserName);
            //微信公众号
            String toUserName = requestMap.get("ToUserName");
            System.out.println("ToUserName+=   "+toUserName);
            // 图文信息
            List<Map<String,String>> articles =  new ArrayList<>();
            if(codes!=null){

+ 76 - 13
svr/svr-base/src/main/java/com/yihu/jw/wx/service/WxMenuService.java

@ -57,7 +57,7 @@ public class WxMenuService extends BaseJpaService<WxMenu, WxMenuDao> {
        }
        String supMenucode = wxMenu.getSupMenucode();
        if(StringUtils.isEmpty(supMenucode)) {//如果是空,则为父菜单
            List<WxMenu> childMenus = findChildMenus(wxMenu.getWechatCode(), wxMenu.getSupMenucode());
            List<WxMenu> childMenus = findChildMenus(wxMenu.getWechatCode(), wxMenu.getCode());
            if(childMenus!=null){
                for(WxMenu wxmenu:childMenus){
                    wxmenu.setStatus(-1);
@ -82,6 +82,15 @@ public class WxMenuService extends BaseJpaService<WxMenu, WxMenuDao> {
        return wxMenuDao.findByWechatCode(wechatCode);
    }
    /**
     * 根据wechatCode查找所有菜单
     * @param wechatCode
     * @return
     */
    public List<WxMenu> findParentMenuByWechatCode(String wechatCode){
        return wxMenuDao.findParentMenuByWechatCode(wechatCode);
    }
    /**
     * 根据wechatCode在微信公众号创建菜单
     * @param wechatCode
@ -145,8 +154,8 @@ public class WxMenuService extends BaseJpaService<WxMenu, WxMenuDao> {
        if(!StringUtils.isEmpty(menu.getType())){
            menuJsonStr += ",\"type\":\"" + menu.getType()+"\"";
        }
        if(!StringUtils.isEmpty(menu.getKey())){
            menuJsonStr += ",\"key\":\"" + menu.getKey()+"\"";
        if(!StringUtils.isEmpty(menu.getMenuKey())){
            menuJsonStr += ",\"key\":\"" + menu.getMenuKey()+"\"";
        }
        if(!StringUtils.isEmpty(menu.getUrl())){
            menuJsonStr += ",\"url\":\"" + menu.getUrl()+"\"";
@ -176,31 +185,85 @@ public class WxMenuService extends BaseJpaService<WxMenu, WxMenuDao> {
    private boolean canSaveOrUpata(WxMenu wxMenu){
        if (StringUtils.isEmpty(wxMenu.getCode())) {
            throw new ApiException(WxContants.WxMenu.message_fail_code_is_null, CommonContants.common_error_params_code);
        }//通过wechatCode查找是否有父菜单,若没有父菜单,则不让创建子菜单
        }
        String wechatCode = wxMenu.getWechatCode();
        if (StringUtils.isEmpty(wechatCode)) {
            throw new ApiException(WxContants.WxMenu.message_fail_wechatCode_is_null, CommonContants.common_error_params_code);
        }
        String name = wxMenu.getName();
        if (StringUtils.isEmpty(name)) {
            throw new ApiException(WxContants.WxMenu.message_fail_name_is_null, CommonContants.common_error_params_code);
        }
        String supMenucode = wxMenu.getSupMenucode();
        if (!StringUtils.isEmpty(supMenucode)) {//不为空,说明是子菜单,判断父菜单是否存在
            //说明是子菜单
            List<WxMenu> childMenus = findChildMenus(wechatCode, supMenucode);
            if(childMenus==null||childMenus.size()==0){
                throw new ApiException(WxContants.WxMenu.message_fail_supMenuCode_is_no_exist, CommonContants.common_error_params_code);
            }
            if(childMenus.size()==5){
                throw new ApiException(WxContants.WxMenu.message_fail_childMenu_is_to_much, CommonContants.common_error_params_code);
            }
            if(name.getBytes().length>60){
                throw new ApiException(WxContants.WxMenu.message_fail_name_is_to_long, CommonContants.common_error_params_code);
            }
            if(StringUtils.isEmpty(wxMenu.getType())){
                throw new ApiException(WxContants.WxMenu.message_fail_type_is_null, CommonContants.common_error_params_code);
            }
        }else{
            //说明是父菜单
            if(name.getBytes().length>16){
                throw new ApiException(WxContants.WxMenu.message_fail_name_is_to_long, CommonContants.common_error_params_code);
            }
            //查找父菜单
            List<WxMenu> parentMenus = findParentMenuByWechatCode(wechatCode);
            if(parentMenus!=null){
                if(parentMenus.size()==3){
                    throw new ApiException(WxContants.WxMenu.message_fail_parentMenu_is_to_much, CommonContants.common_error_params_code);
                }
            }
        }
        if (StringUtils.isEmpty(wxMenu.getName())) {
            throw new ApiException(WxContants.WxMenu.message_fail_name_is_null, CommonContants.common_error_params_code);
        }
        if(StringUtils.isEmpty(wxMenu.getType())){
            throw new ApiException(WxContants.WxMenu.message_fail_type_is_null, CommonContants.common_error_params_code);
        String type1=wxMenu.getType();
        if(type1==null){
            type1="";
        }
        if("click".equals(wxMenu.getType().toUpperCase())){
            String key = wxMenu.getKey();
        String type = type1.toUpperCase();
        if("click".equals(type)){
            String key = wxMenu.getMenuKey();
            if(StringUtils.isEmpty(key)){
                throw new ApiException(WxContants.WxMenu.message_fail_wxMenuKey_is_null, CommonContants.common_error_params_code);
                throw new ApiException(WxContants.WxMenu.message_fail_key_is_null, CommonContants.common_error_params_code);
            }
            if(key.getBytes().length>128){
                throw new ApiException(WxContants.WxMenu.message_fail_wxMenuKey_is_toLong, CommonContants.common_error_params_code);
                throw new ApiException(WxContants.WxMenu.message_fail_key_is_toLong, CommonContants.common_error_params_code);
            }
        }
        String url = wxMenu.getUrl();
        if("view".equals(type)){
            if(StringUtils.isEmpty(url)){
                throw new ApiException(WxContants.WxMenu.message_fail_url_is_null, CommonContants.common_error_params_code);
            }
            if(url.getBytes().length>128){
                throw new ApiException(WxContants.WxMenu.message_fail_url_is_toLong, CommonContants.common_error_params_code);
            }
        }
        if("miniprogram".equals(type)){
            if(StringUtils.isEmpty(url)){
                throw new ApiException(WxContants.WxMenu.message_fail_url_is_null, CommonContants.common_error_params_code);
            }
            if(url.getBytes().length>128){
                throw new ApiException(WxContants.WxMenu.message_fail_url_is_toLong, CommonContants.common_error_params_code);
            }
            if(StringUtils.isEmpty(wxMenu.getAppid())){
                throw new ApiException(WxContants.WxMenu.message_fail_appid_is_null, CommonContants.common_error_params_code);
            }
            if(StringUtils.isEmpty(wxMenu.getPagepath())){
                throw new ApiException(WxContants.WxMenu.message_fail_pagepath_is_null, CommonContants.common_error_params_code);
            }
        }
        if("media_id".equals(type)||"view_limited".equals(type)){
            if(StringUtils.isEmpty(wxMenu.getMediaId())){
                throw new ApiException(WxContants.WxMenu.message_fail_mediaId_is_null, CommonContants.common_error_params_code);
            }
        }
        if(StringUtils.isEmpty(wxMenu.getSort())){