添加微信相关代码

master
bynt 2 years ago
parent 818cf08000
commit 58a79d1f2e

@ -0,0 +1,74 @@
/*
* Copyright (c) 2020 pig4cloud Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.baiye.constant;
/**
* @author lengleng
* @date 2019/2/1
*/
public interface WeChatRequestConstants {
/**
*
*/
String GET_QR_CODE = "/wechat/v1/ios";
/**
* 退
*/
String WE_CHAT_LOGOUT = "/wechat/v1/batchLogout";
/**
*
*/
String WE_CHAT_SEND_TXT = "/wechat/v1/sendtext";
/**
*
*/
String WE_CHAT_SEND_PICTURE = "/wechat/v1/sendurlpic";
/**
* gif
*/
String WE_CHAT_SEND_GIF = "/wechat/v1/sendGif";
/**
*
*/
String WE_CHAT_SEND_VIDEO = "/wechat/v1/sendCdnVideoMsg";
/**
*
*/
String WE_CHAT_FRIEND_INFORMATION = "/wechat/v1/friendinfo";
/**
*
*/
String WE_CHAT_ADD_FRIEND = "/wechat/v1/addfriends";
/**
* 线
*/
String WE_CHAT_STATUS = " /wechat/v1/wecatstatus";
}

@ -0,0 +1,25 @@
package com.baiye.http;
import lombok.Data;
import java.io.Serializable;
/**
* @author Enzo
* @date : 2022/6/23
*/
@Data
public class WeChatResponse<T extends Serializable> implements Serializable {
private static final long serialVersionUID = 6763956796736587193L;
private T data;
private String msg;
private Integer status;
private Boolean success;
}

@ -0,0 +1,19 @@
package com.baiye.model.dto;
import lombok.Data;
import java.io.Serializable;
/**
* @author Enzo
* @date : 2022/6/24
*/
@Data
public class WeChatQrCodeDTO implements Serializable {
private static final long serialVersionUID = 5388401222056549488L;
private String wechat;
private String uuid;
}

@ -111,10 +111,15 @@ public enum ResponseCode {
/**
*
*
*
*/
CONNECTION_SUCCEEDED("1027", "连接成功"),
/**
*
*
*/
FAILED_GET_QR_CODE("1028", "获取二维码失败"),
/**
*
*

@ -0,0 +1,22 @@
package com.baiye.config.properties;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* @author Enzo
* @date : 2022/6/24
*/
@Getter
@Setter
@Component
@ConfigurationProperties(prefix = "wechat")
public class WeChatProperties {
@ApiModelProperty("请求地址")
private String gatewayHost;
}

@ -151,6 +151,7 @@ public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {
.antMatchers( "/api/report/turnOn").permitAll()
.antMatchers( "/api/users/info/findById").permitAll()
.antMatchers( "/api/users/info/findIsReview").permitAll()
.antMatchers( "/api/wechat/**").permitAll()
// 支付回调
.antMatchers( "/pay/aliPay/pay-notify").permitAll()
// 自定义匿名访问所有url放行允许匿名和带Token访问细腻化到每个 Request 类型

@ -0,0 +1,29 @@
package com.baiye.modules.system.domain;
import com.baiye.model.base.BaseEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
/**
* @author Enzo
* @date : 2022/6/23
*/
@Entity
@Getter
@Setter
@Table(name="tb_wechat_user")
@EntityListeners(AuditingEntityListener.class)
public class WeChatUser extends BaseEntity {
private static final long serialVersionUID = -4755997517585953316L;
@Id
@Column(name = "id")
@ApiModelProperty(value = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
}

@ -0,0 +1,29 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.baiye.modules.system.repository;
import com.baiye.modules.system.domain.WeChatUser;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
/**
* @author Zheng Jie
* @date 2018-11-22
*/
public interface WeChatRepository extends JpaRepository<WeChatUser, Long>, JpaSpecificationExecutor<WeChatUser> {
}

@ -0,0 +1,36 @@
package com.baiye.modules.system.rest;
import com.baiye.http.WeChatResponse;
import com.baiye.modules.system.service.WeChatUserService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author Enzo
* @date : 2022/6/24
*/
@RestController
@Api(tags = "微信回调")
@RequestMapping("/wechat")
@RequiredArgsConstructor
public class WeChatCallbackController {
private final WeChatUserService weChatUserService;
/**
*
* @param weChatResponse
* @return
*/
@PostMapping(value = "/callback")
public ResponseEntity<String> frontRcvResponse(@RequestBody WeChatResponse weChatResponse) {
weChatUserService.analyticalData(weChatResponse);
return new ResponseEntity<>(HttpStatus.OK);
}
}

@ -0,0 +1,36 @@
package com.baiye.modules.system.rest;
import com.baiye.http.CommonResponse;
import com.baiye.modules.system.service.WeChatUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author Enzo
* @date : 2022/6/23
*/
@RestController
@Api(tags = "微信相关接口")
@RequestMapping("/api/wechat")
@RequiredArgsConstructor
public class WechatController {
private final WeChatUserService weChatUserService;
@ApiOperation("获取二维码")
@PostMapping("/getQrCode")
public CommonResponse<String> read(String wechatId) {
return CommonResponse.createBySuccess
(weChatUserService.getQrCode(wechatId));
}
}

@ -0,0 +1,24 @@
package com.baiye.modules.system.service;
import com.baiye.http.WeChatResponse;
/**
* @author Enzo
* @date : 2022/6/23
*/
public interface WeChatUserService {
/**
*
* @param wechatId
* @return
*/
String getQrCode(String wechatId);
/**
*
* @param weChatResponse
*/
void analyticalData(WeChatResponse weChatResponse);
}

@ -55,9 +55,8 @@ import java.util.*;
@RequiredArgsConstructor
public class UserMessageServiceImpl implements UserMessageService {
private final UserMessageRepository userMessageRepository;
private final AutoReminderService autoReminderService;
private final UserMessageMapper userMessageMapper;

@ -0,0 +1,55 @@
package com.baiye.modules.system.service.impl;
import cn.hutool.core.util.IdUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.baiye.config.properties.WeChatProperties;
import com.baiye.constant.WeChatRequestConstants;
import com.baiye.exception.BadRequestException;
import com.baiye.http.WeChatResponse;
import com.baiye.model.enums.ResponseCode;
import com.baiye.modules.system.repository.WeChatRepository;
import com.baiye.modules.system.service.WeChatUserService;
import com.google.common.collect.ImmutableMap;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
/**
* @author Enzo
* @date : 2022/6/23
*/
@Service
@RequiredArgsConstructor
public class WeChatUserServiceImpl implements WeChatUserService {
private final WeChatRepository weChatRepository;
private final WeChatProperties weChatProperties;
@Override
public String getQrCode(String wechatId) {
Map<String, Object> getQrCodeMap =
ImmutableMap.of("uuid", IdUtil.randomUUID());
if (StringUtils.isNotBlank(wechatId)){
getQrCodeMap.put("wechat", wechatId);
}
String getQrCodeResult = HttpUtil.get
(weChatProperties.getGatewayHost().
concat(WeChatRequestConstants.GET_QR_CODE), getQrCodeMap);
if (getQrCodeResult.contains(ResponseCode.SUCCESS.getDesc())) {
WeChatResponse weChatResponse =
JSONUtil.toBean(getQrCodeResult, WeChatResponse.class);
return weChatResponse.getMsg();
}
throw new BadRequestException(ResponseCode.FAILED_GET_QR_CODE.getDesc());
}
@Override
public void analyticalData(WeChatResponse weChatResponse) {
}
}

@ -168,4 +168,7 @@ debt:
visitUrl: http://8.130.96.163:8800/pages/login#/pages/statisticsForm/index?userId=
qrcodeUrl: /home/eladmin/qrcode/
qrcodeLogo: /home/eladmin/qrcode/qrcode.jpg
reqUrl: /qrcode/
reqUrl: /qrcode/
wechat:
gatewayHost: byqw.wework.uat.robot.ecofanli.com

Loading…
Cancel
Save