修改耗材库存
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
package com.chaozhanggui.system.cashierservice.controller;
|
||||
|
||||
import com.chaozhanggui.system.cashierservice.dao.TbUserShopMsgMapper;
|
||||
import com.chaozhanggui.system.cashierservice.sign.Result;
|
||||
import com.chaozhanggui.system.cashierservice.util.JSONUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.mp.api.WxMpConfigStorage;
|
||||
import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
|
||||
import me.chanjar.weixin.mp.api.WxMpQrcodeService;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.*;
|
||||
|
||||
@CrossOrigin(origins = "*")
|
||||
@RestController
|
||||
@Slf4j
|
||||
@RequestMapping("qrcode")
|
||||
public class QrCodeController {
|
||||
|
||||
@Autowired
|
||||
TbUserShopMsgMapper tbUserShopMsgMapper;
|
||||
|
||||
|
||||
// public Result scanCode(){
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
@RequestMapping("/getscanCode")
|
||||
public void getscanCode(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
|
||||
log.info("****************来自微信服务器的请求:{}", request.getMethod().toUpperCase());
|
||||
//微信服务器POST请求时,用的是UTF-8编码,在接收时也要用同样的编码,否则中文乱码
|
||||
request.setCharacterEncoding("UTF-8");
|
||||
//响应消息时,也要设置同样的编码
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
//判断请求方式是否是post
|
||||
boolean isPost = Objects.equals("POST", request.getMethod().toUpperCase());
|
||||
if(isPost){
|
||||
|
||||
Map map= request.getParameterMap();
|
||||
|
||||
log.info("map:{}",JSONUtil.toJSONString(map));
|
||||
|
||||
}else {
|
||||
String signature=request.getParameter("signature");
|
||||
String timestamp=request.getParameter("timestamp");
|
||||
String nonce=request.getParameter("nonce");
|
||||
String echostr=request.getParameter("echostr");
|
||||
|
||||
if (StringUtils.isEmpty(signature) || StringUtils.isEmpty(timestamp) || StringUtils.isEmpty(nonce) || StringUtils.isEmpty(echostr)) {
|
||||
return ;
|
||||
}
|
||||
|
||||
String token="chaozhanggui123";
|
||||
|
||||
List<String> list= Arrays.asList(token,timestamp,nonce);
|
||||
Collections.sort(list);
|
||||
StringBuffer sb=new StringBuffer();
|
||||
for(String s: list){
|
||||
sb.append(s);
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
MessageDigest instance = MessageDigest.getInstance("sha1");
|
||||
//使用sha1进行加密,获得byte数组
|
||||
byte[] digest = instance.digest(sb.toString().getBytes());
|
||||
StringBuilder sum = new StringBuilder();
|
||||
for (byte b : digest) {
|
||||
sum.append(Integer.toHexString((b >> 4) & 15));
|
||||
sum.append(Integer.toHexString(b & 15));
|
||||
}
|
||||
// 3)开发者获得加密后的字符串可与 signature 对比,标识该请求来源于微信
|
||||
if (!StringUtils.isEmpty(signature) && signature.equals(sum.toString())) {
|
||||
response.getWriter().write(echostr);
|
||||
return;
|
||||
}
|
||||
response.getWriter().write("");
|
||||
return;
|
||||
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
response.getWriter().write("");
|
||||
return;
|
||||
}
|
||||
}
|
||||
public static void main(String[] args){
|
||||
WxMpInMemoryConfigStorage configStorage=new WxMpInMemoryConfigStorage();
|
||||
|
||||
configStorage.setAppId("wxdd2b72cc2c40c979");
|
||||
configStorage.setSecret("4d909d8dbe3e6e7ac31055fa03dcee4b");
|
||||
// configStorage.setAccessToken("");
|
||||
// configStorage.setAesKey("");
|
||||
|
||||
|
||||
|
||||
WxMpService wxMpService=new WxMpServiceImpl();
|
||||
|
||||
wxMpService.setWxMpConfigStorage(configStorage);
|
||||
|
||||
|
||||
try {
|
||||
WxMpQrCodeTicket ticket= wxMpService.getQrcodeService().qrCodeCreateLastTicket("哈哈哈哈哈哈哈哈哈哈哈哈");
|
||||
System.out.println(JSONUtil.toJSONString(ticket));
|
||||
} catch (WxErrorException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user