|
|
|
@ -1,6 +1,9 @@
|
|
|
|
|
package com.java3y.austin.web.controller;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import com.google.common.base.Throwables;
|
|
|
|
|
import com.java3y.austin.common.enums.RespStatusEnum;
|
|
|
|
|
import com.java3y.austin.common.vo.BasicResultVO;
|
|
|
|
@ -11,12 +14,17 @@ import io.swagger.annotations.Api;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import me.chanjar.weixin.mp.api.WxMpService;
|
|
|
|
|
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;
|
|
|
|
|
import me.chanjar.weixin.mp.bean.template.WxMpTemplate;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 微信服务号
|
|
|
|
@ -79,4 +87,50 @@ public class OfficialAccountController {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 接收微信的事件消息
|
|
|
|
|
* https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Access_Overview.html
|
|
|
|
|
* 临时给微信服务号登录使用,正常消息推送平台不会有此接口
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping("/receipt")
|
|
|
|
|
@ApiOperation("/接收微信的事件消息")
|
|
|
|
|
public String receiptMessage(String signature, String timestamp, String nonce, String echostr) {
|
|
|
|
|
log.info("get weixin signature:{},:{},nonce:{},echostr:{}", signature, timestamp, nonce, echostr);
|
|
|
|
|
if (StrUtil.isNotBlank(echostr)) {
|
|
|
|
|
return echostr;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 临时给微信服务号登录使用(生成二维码),正常消息推送平台不会有此接口
|
|
|
|
|
*
|
|
|
|
|
* @param accountId 消息推送平台体系内的Id
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping("/qrCode")
|
|
|
|
|
@ApiOperation("/生成 服务号 二维码")
|
|
|
|
|
public BasicResultVO getQrCode(Long accountId) {
|
|
|
|
|
if (accountId == null) {
|
|
|
|
|
return BasicResultVO.fail(RespStatusEnum.CLIENT_BAD_PARAMETERS);
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
// 生成随机值,获取服务号二维码 且 用于校验登录
|
|
|
|
|
String id = IdUtil.getSnowflake().nextIdStr();
|
|
|
|
|
WxMpService wxMpService = wxServiceUtils.getOfficialAccountServiceMap().get(accountId);
|
|
|
|
|
WxMpQrCodeTicket ticket = wxMpService.getQrcodeService().qrCodeCreateTmpTicket(id, 2592000);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String url = wxMpService.getQrcodeService().qrCodePictureUrl(ticket.getTicket());
|
|
|
|
|
Map<Object, Object> result = MapUtil.of(new String[][]{{"url", url}, {"id", id}});
|
|
|
|
|
return BasicResultVO.success(result);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("OfficialAccountController#getQrCode fail:{}", Throwables.getStackTraceAsString(e));
|
|
|
|
|
return BasicResultVO.fail(RespStatusEnum.SERVICE_ERROR);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|