|
@@ -14,14 +14,25 @@ import com.qmrb.system.pojo.vo.UserInfo;
|
|
|
import com.qmrb.system.pojo.vo.WxLoginVO;
|
|
|
import com.qmrb.system.service.ToolWxConfigService;
|
|
|
import com.qmrb.system.service.UserService;
|
|
|
+import com.qmrb.system.utils.QRCodeUtil;
|
|
|
import com.qmrb.system.utils.WxPayUtil;
|
|
|
import com.qmrb.system.wxpayback.Enum.WxApiType;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.codec.binary.Base64;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.imageio.ImageIO;
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.io.PrintWriter;
|
|
|
+import java.net.URL;
|
|
|
+import java.net.URLConnection;
|
|
|
+
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -71,6 +82,20 @@ public class UserServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
String access_token = jsonObject.getStr("access_token");
|
|
|
return access_token;
|
|
|
}
|
|
|
+
|
|
|
+ public String getWxAccessToken(ToolWxConfig wxConfig){
|
|
|
+ //获取当前的openid
|
|
|
+ Map hashMap = new HashMap();
|
|
|
+ hashMap.put("appid", wxConfig.getAppId());
|
|
|
+ hashMap.put("secret", wxConfig.getAppSecret());
|
|
|
+// hashMap.put("js_code", code);
|
|
|
+ hashMap.put("grant_type", "client_credential");
|
|
|
+ String json = HttpUtil.get(WxApiType.WX_TOKEN.getValue(), hashMap);
|
|
|
+ JSONObject jsonObject = JSONUtil.parseObj(json);
|
|
|
+ log.info("json:{}",jsonObject);
|
|
|
+ String access_token = jsonObject.getStr("access_token");
|
|
|
+ return access_token;
|
|
|
+ }
|
|
|
|
|
|
public String getUserPhoneNumber(ToolWxConfig wxConfig, String code){
|
|
|
String token = getWxAccessToken(wxConfig, code);
|
|
@@ -91,6 +116,102 @@ public class UserServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
return mobile;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public String getCouponQRCode(ToolWxConfig conf, String key) {
|
|
|
+ String token = getWxAccessToken(conf);
|
|
|
+ //获取当前的openid
|
|
|
+ // Map hashMap = new HashMap();
|
|
|
+ // hashMap.put("page", "pages/index/index");
|
|
|
+ // hashMap.put("scene", "contractId=" + key);
|
|
|
+ // hashMap.put("env_version", "develop");
|
|
|
+ // // hashMap.put("width", 430);
|
|
|
+ // // hashMap.put("auto_color", false);
|
|
|
+ // // hashMap.put("line_color", "{\"r\":\"0\",\"g\":\"0\",\"b\":\"0\"}");
|
|
|
+ // // hashMap.put("is_hyaline", false);
|
|
|
+ // String url = WxApiType.GET_QRCODE_URL.getValue()+"?access_token="+token;
|
|
|
+ // String json = HttpUtil.post(url, JSONUtil.toJsonStr(hashMap));
|
|
|
+ // log.info("获取微信二维码:{}",json);
|
|
|
+ // byte[] bytes = json.getBytes();
|
|
|
+ //
|
|
|
+ //
|
|
|
+ // String data = Base64.getEncoder().encodeToString(bytes);
|
|
|
+ // return data;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ Map<String, Object> resultObj = new HashMap();
|
|
|
+ PrintWriter out = null;
|
|
|
+ //BufferedReader in = null;
|
|
|
+ InputStream in = null;
|
|
|
+ String result = "";
|
|
|
+ try {
|
|
|
+ URL realUrl = new URL("https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token="+token);
|
|
|
+ // 打开和URL之间的连接
|
|
|
+ URLConnection conn = realUrl.openConnection();
|
|
|
+ // 设置通用的请求属性
|
|
|
+ conn.setRequestProperty("accept", "*/*");
|
|
|
+ conn.setRequestProperty("connection", "Keep-Alive");
|
|
|
+ conn.setRequestProperty("user-agent",
|
|
|
+ "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
|
|
|
+ // 发送POST请求必须设置如下两行
|
|
|
+ conn.setDoOutput(true);
|
|
|
+ conn.setDoInput(true);
|
|
|
+ // 获取URLConnection对象对应的输出流
|
|
|
+ out = new PrintWriter(conn.getOutputStream());
|
|
|
+ // 发送请求参数
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("scene", "contractId=" + key); //参数自定义
|
|
|
+ jsonObject.put("page","pages/index/index");//要生成小程序码的链接
|
|
|
+ jsonObject.put("width",300);
|
|
|
+ jsonObject.put("env_version", "develop");
|
|
|
+ out.print(jsonObject);
|
|
|
+ // flush输出流的缓冲
|
|
|
+ out.flush();
|
|
|
+ in = conn.getInputStream();
|
|
|
+ byte[] data = null;
|
|
|
+ // 读取图片字节数组
|
|
|
+ try {
|
|
|
+ ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
|
|
|
+ byte[] buff = new byte[100];
|
|
|
+ int rc = 0;
|
|
|
+ while ((rc = in.read(buff, 0, 100)) > 0) {
|
|
|
+ swapStream.write(buff, 0, rc);
|
|
|
+ }
|
|
|
+ data = swapStream.toByteArray();
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("获取领券二维码出错",e);
|
|
|
+ } finally {
|
|
|
+ if (in != null) {
|
|
|
+ try {
|
|
|
+ in.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("获取领券二维码出错",e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return new String(Base64.encodeBase64(data));
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println("发送 POST 请求出现异常!" + e);
|
|
|
+ log.error("发送 POST 请求出现异常!",e);
|
|
|
+ }
|
|
|
+ // 使用finally块来关闭输出流、输入流
|
|
|
+ finally {
|
|
|
+ try {
|
|
|
+ if (out != null) {
|
|
|
+ out.close();
|
|
|
+ }
|
|
|
+ if (in != null) {
|
|
|
+ in.close();
|
|
|
+ }
|
|
|
+ } catch (IOException ex) {
|
|
|
+ log.error("关闭输出流、输入流!",ex);
|
|
|
+ }
|
|
|
+ }
|
|
|
+// resultObj.put("result",result);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
public UserInfo getMyInfo(UserParam userParam){
|
|
|
UserInfo userInfo = new UserInfo();
|
|
|
userInfo.setId("1");
|