Shanks 7 gadi atpakaļ
vecāks
revīzija
90d3bd86b6

+ 5 - 0
pom.xml

@@ -103,6 +103,11 @@
 			<artifactId>nekohtml</artifactId>
 			<version>1.9.22</version>
 		</dependency>
+		<dependency>
+			<groupId>org.bouncycastle</groupId>
+			<artifactId>bcprov-jdk15on</artifactId>
+			<version>1.54</version>
+		</dependency>
 	</dependencies>
 
 	<build>

+ 5 - 1
src/main/java/com/ygj/yuemum/controller/global/WeChatInfoController.java

@@ -4,6 +4,7 @@ package com.ygj.yuemum.controller.global;
 import com.ygj.yuemum.service.global.WeChatInfoService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
@@ -28,5 +29,8 @@ public class WeChatInfoController {
     public Map<String,String> getWXOpenid(@RequestParam("js_code") String js_code) {
         return saveWeChatInfo.getWXOpenid(js_code);
     }
-
+    @PostMapping("/getWxDecrypt")
+    public String getWxDecrypt(@RequestParam("encrypData") String encrypData, @RequestParam("ivData") String ivData, @RequestParam("openid") String openid) {
+        return saveWeChatInfo.getWxDecrypt(encrypData,ivData,openid);
+    }
 }

+ 38 - 0
src/main/java/com/ygj/yuemum/controller/wxmini/WXUserAddressController.java

@@ -0,0 +1,38 @@
+package com.ygj.yuemum.controller.wxmini;
+
+
+import com.ygj.yuemum.domain.wxmini.WXUserAddress;
+import com.ygj.yuemum.service.wxmini.WXUserAddressService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@RestController
+public class WXUserAddressController {
+
+    @Autowired
+    private WXUserAddressService wxUserAddressService;
+    @GetMapping("/getWXUserAddress")
+    public List<WXUserAddress> getWXUserAddress(@RequestParam("xu_openid") String xu_openid) {
+        List<WXUserAddress> wxUserAddresses = wxUserAddressService.getWXUserAddress(xu_openid);
+        return wxUserAddresses;
+    }
+
+    @PostMapping("/insertWXUserAddress")
+    public int insertWXUserAddress(@ModelAttribute WXUserAddress wxUserAddress) {
+        return wxUserAddressService.insertWXUserAddress(wxUserAddress);
+    }
+    @PostMapping("/updateWXUserAddress")
+    public int updateWXUserAddress(@ModelAttribute WXUserAddress wxUserAddress) {
+        return wxUserAddressService.updateWXUserAddress(wxUserAddress);
+    }
+    @GetMapping("/updateWXUserDefAddress")
+    public int updateWXUserDefAddress(@RequestParam("id") Integer id) {
+        return wxUserAddressService.updateWXUserDefAddress(id);
+    }
+    @GetMapping("/deleteWXUserDefAddress")
+    public int deleteWXUserDefAddress(@RequestParam("id") Integer id) {
+        return wxUserAddressService.deleteWXUserDefAddress(id);
+    }
+}

+ 16 - 0
src/main/java/com/ygj/yuemum/dao/wxmini/WXUserAddressDao.java

@@ -0,0 +1,16 @@
+package com.ygj.yuemum.dao.wxmini;
+
+import com.ygj.yuemum.domain.wxmini.WXUserAddress;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+@Repository
+public interface WXUserAddressDao {
+    List<WXUserAddress> getWXUserAddress(String xu_openid);
+    int insertWXUserAddress(WXUserAddress wxUserAddress);
+    int updateWXUserAddress(WXUserAddress wxUserAddress);
+    int updateWXUserDefAddress (Integer id);
+    int getWXUserAddressCount(String xu_openid);
+    int deleteWXUserDefAddress (Integer id);
+}

+ 76 - 0
src/main/java/com/ygj/yuemum/domain/wxmini/WXUserAddress.java

@@ -0,0 +1,76 @@
+package com.ygj.yuemum.domain.wxmini;
+
+public class WXUserAddress {
+    private Integer id;
+    private String xu_openid;
+    private String xa_phone;
+    private String xa_consignee;
+    private String xa_city;
+    private String xa_county;
+    private String xa_address;
+    private Integer xa_default;
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public String getXu_openid() {
+        return xu_openid;
+    }
+
+    public void setXu_openid(String xu_openid) {
+        this.xu_openid = xu_openid;
+    }
+
+    public String getXa_phone() {
+        return xa_phone;
+    }
+
+    public void setXa_phone(String xa_phone) {
+        this.xa_phone = xa_phone;
+    }
+
+    public String getXa_consignee() {
+        return xa_consignee;
+    }
+
+    public void setXa_consignee(String xa_consignee) {
+        this.xa_consignee = xa_consignee;
+    }
+
+    public String getXa_city() {
+        return xa_city;
+    }
+
+    public void setXa_city(String xa_city) {
+        this.xa_city = xa_city;
+    }
+
+    public String getXa_address() {
+        return xa_address;
+    }
+
+    public void setXa_address(String xa_address) {
+        this.xa_address = xa_address;
+    }
+
+    public String getXa_county() {
+        return xa_county;
+    }
+
+    public void setXa_county(String xa_county) {
+        this.xa_county = xa_county;
+    }
+
+    public Integer getXa_default() {
+        return xa_default;
+    }
+
+    public void setXa_default(Integer xa_default) {
+        this.xa_default = xa_default;
+    }
+}

+ 72 - 2
src/main/java/com/ygj/yuemum/service/global/WeChatInfoService.java

@@ -5,15 +5,23 @@ import com.ygj.yuemum.dao.global.WeChatInfoDao;
 import com.ygj.yuemum.domain.global.WeChatInfo;
 import com.ygj.yuemum.domain.wxmini.WXUser;
 import com.ygj.yuemum.service.wxmini.WXUserService;
+import org.apache.commons.codec.binary.Base64;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import javax.crypto.BadPaddingException;
+import javax.crypto.Cipher;
+import javax.crypto.IllegalBlockSizeException;
+import javax.crypto.NoSuchPaddingException;
+import javax.crypto.spec.IvParameterSpec;
+import javax.crypto.spec.SecretKeySpec;
 import java.io.BufferedReader;
 import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
 import java.net.URL;
 import java.net.URLConnection;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
+import java.security.*;
+import java.security.spec.InvalidParameterSpecException;
 import java.text.SimpleDateFormat;
 import java.util.*;
 
@@ -81,6 +89,7 @@ public class WeChatInfoService {
             result.put("openid", openid);
             result.put("type","2");
             result.put("nickName",ckeckwxUser.getXu_name());
+            result.put("phone",ckeckwxUser.getXu_phone());
         } else {
             WXUser wxUser = new WXUser();
             wxUser.setXu_openid(openid);
@@ -195,4 +204,65 @@ public class WeChatInfoService {
         }
         return jsonStr.toString();
     }
+    public String getWxDecrypt(String encrypdata,String ivdata, String openid) {
+        WXUser wxUser = wxUserService.getWXUser(openid);
+        String str="";
+        try {
+            str = decrypt(encrypdata,wxUser.getXu_sessionkey(),ivdata,"UTF-8");
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        System.out.println(str);
+        return str;
+    }
+    public static String decrypt(String data, String key, String iv, String encodingFormat) throws Exception {
+//        initialize();
+
+        //被加密的数据
+        byte[] dataByte = Base64.decodeBase64(data);
+        //加密秘钥
+        byte[] keyByte = Base64.decodeBase64(key);
+        //偏移量
+        byte[] ivByte = Base64.decodeBase64(iv);
+
+
+        try {
+            Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
+            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding");
+
+            SecretKeySpec spec = new SecretKeySpec(keyByte, "AES");
+
+            AlgorithmParameters parameters = AlgorithmParameters.getInstance("AES");
+
+            parameters.init(new IvParameterSpec(ivByte));
+
+            cipher.init(Cipher.DECRYPT_MODE, spec, parameters);// 初始化
+
+            byte[] resultByte = cipher.doFinal(dataByte);
+            if (null != resultByte && resultByte.length > 0) {
+                String result = new String(resultByte, encodingFormat);
+                return result;
+            }
+            return null;
+        } catch (NoSuchAlgorithmException e) {
+            e.printStackTrace();
+        } catch (NoSuchPaddingException e) {
+            e.printStackTrace();
+        } catch (InvalidParameterSpecException e) {
+            e.printStackTrace();
+        } catch (InvalidKeyException e) {
+            e.printStackTrace();
+        } catch (InvalidAlgorithmParameterException e) {
+            e.printStackTrace();
+        } catch (IllegalBlockSizeException e) {
+            e.printStackTrace();
+        } catch (BadPaddingException e) {
+            e.printStackTrace();
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        }
+
+        return null;
+    }
+
 }

+ 41 - 0
src/main/java/com/ygj/yuemum/service/wxmini/WXUserAddressService.java

@@ -0,0 +1,41 @@
+package com.ygj.yuemum.service.wxmini;
+
+import com.ygj.yuemum.dao.wxmini.WXUserAddressDao;
+import com.ygj.yuemum.domain.wxmini.WXUserAddress;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class WXUserAddressService {
+
+    @Autowired
+
+    private WXUserAddressDao wxUserAddressDao;
+
+    public List<WXUserAddress> getWXUserAddress(String xu_openid) {
+        return wxUserAddressDao.getWXUserAddress(xu_openid);
+    }
+    public int insertWXUserAddress(WXUserAddress wxUserAddress){
+        //xa_default
+        int addressCount = wxUserAddressDao.getWXUserAddressCount(wxUserAddress.getXu_openid());
+        if (addressCount > 0) {
+            wxUserAddress.setXa_default(0);
+        } else {
+            wxUserAddress.setXa_default(1);
+        }
+        return wxUserAddressDao.insertWXUserAddress(wxUserAddress);
+    }
+    public int updateWXUserAddress(WXUserAddress wxUserAddress){
+        return wxUserAddressDao.updateWXUserAddress(wxUserAddress);
+    }
+    public int updateWXUserDefAddress(Integer id){
+        return wxUserAddressDao.updateWXUserDefAddress(id);
+    }
+    public int deleteWXUserDefAddress(Integer id) {
+        return wxUserAddressDao.deleteWXUserDefAddress(id);
+    }
+
+
+}

+ 121 - 0
src/main/resources/mybatis/mapper/wxmini/WXUserAddressMapper.xml

@@ -0,0 +1,121 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
+<mapper namespace="com.ygj.yuemum.dao.wxmini.WXUserAddressDao">
+
+    <resultMap id="BaseResultMap" type="com.ygj.yuemum.domain.wxmini.WXUserAddress">
+        <id column="id" property="id" jdbcType="INTEGER"/>
+        <result column="xu_openid" property="xu_openid" jdbcType="VARCHAR"/>
+        <result column="xa_phone" property="xa_phone" jdbcType="VARCHAR"/>
+        <result column="xa_consignee" property="xa_consignee" jdbcType="VARCHAR"/>
+        <result column="xa_city" property="xa_city" jdbcType="VARCHAR"/>
+        <result column="xa_county" property="xa_county" jdbcType="VARCHAR"/>
+        <result column="xa_address" property="xa_address" jdbcType="VARCHAR"/>
+        <result column="xa_default" property="xa_default" jdbcType="INTEGER"/>
+    </resultMap>
+
+    <!--获取所有数据-->
+    <select id="getWXUserAddress" resultType="com.ygj.yuemum.domain.wxmini.WXUserAddress" parameterType="java.lang.String">
+        select
+        id,xu_openid,xa_phone,xa_consignee,xa_city,xa_county,xa_address,xa_default
+        from wx_user_address
+        where xu_openid = #{xu_openid,jdbcType=VARCHAR}
+        order by xa_default desc,id asc
+    </select>
+
+    <select id="getWXUserAddressCount" resultType="java.lang.Integer" parameterType="java.lang.String">
+        select
+        count(1)
+        from wx_user_address
+        where xu_openid = #{xu_openid,jdbcType=VARCHAR}
+        order by xa_default desc,id asc
+    </select>
+
+    <insert id="insertWXUserAddress" parameterType="com.ygj.yuemum.domain.wxmini.WXUserAddress" >
+        insert into wx_user_address
+        <trim prefix="(" suffix=")" suffixOverrides="," >
+            <if test="xu_openid != null" >
+                xu_openid,
+            </if>
+            <if test="xa_phone != null" >
+                xa_phone,
+            </if>
+            <if test="xa_consignee != null" >
+                xa_consignee,
+            </if>
+            <if test="xa_city != null" >
+                xa_city,
+            </if>
+            <if test="xa_county != null" >
+                xa_county,
+            </if>
+            <if test="xa_address != null" >
+                xa_address,
+            </if>
+            <if test="xa_default != null" >
+                xa_default
+            </if>
+        </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides="," >
+            <if test="xu_openid != null" >
+                #{xu_openid,jdbcType=VARCHAR},
+            </if>
+            <if test="xa_phone != null" >
+                #{xa_phone,jdbcType=VARCHAR},
+            </if>
+            <if test="xa_consignee != null" >
+                #{xa_consignee,jdbcType=VARCHAR},
+            </if>
+            <if test="xa_city != null" >
+                #{xa_city,jdbcType=VARCHAR},
+            </if>
+            <if test="xa_county != null" >
+                #{xa_county,jdbcType=VARCHAR},
+            </if>
+            <if test="xa_address != null" >
+                #{xa_address,jdbcType=VARCHAR},
+            </if>
+            <if test="xa_default != null" >
+                #{xa_default,jdbcType=INTEGER},
+            </if>
+        </trim>
+    </insert>
+
+    <update id="updateWXUserAddress" parameterType="com.ygj.yuemum.domain.wxmini.WXUserAddress" >
+        update wx_user_address
+        <set >
+            <if test="xu_openid != null" >
+                xu_openid = #{xu_openid,jdbcType=VARCHAR},
+            </if>
+            <if test="xa_phone != null" >
+                xa_phone = #{xa_phone,jdbcType=VARCHAR},
+            </if>
+            <if test="xa_consignee != null" >
+                xa_consignee = #{xa_consignee,jdbcType=VARCHAR},
+            </if>
+            <if test="xa_city != null" >
+                xa_city = #{xa_city,jdbcType=VARCHAR},
+            </if>
+            <if test="xa_county != null" >
+                xa_county = #{xa_county,jdbcType=VARCHAR},
+            </if>
+            <if test="xa_address != null" >
+                xa_address = #{xa_address,jdbcType=VARCHAR},
+            </if>
+            <if test="xa_default != null" >
+                xa_default = #{xa_default,jdbcType=INTEGER}
+            </if>
+        </set>
+        where id = #{id,jdbcType=INTEGER}
+    </update>
+
+
+    <update id="updateWXUserDefAddress" parameterType="java.lang.Integer" >
+        update wx_user_address
+        set xa_default = if( id = #{id,jdbcType=INTEGER},1,0)
+    </update>
+
+    <delete id="deleteWXUserDefAddress" parameterType="java.lang.Integer">
+        delete from wx_user_address
+        where id = #{id,jdbcType=INTEGER}
+    </delete>
+</mapper>