Browse Source

add 分享商品CODE

he2802 2 years ago
parent
commit
8bdb49bbe8

+ 14 - 0
zhongzheng-admin/src/main/java/com/zhongzheng/controller/common/CommonController.java

@@ -11,6 +11,7 @@ import com.zhongzheng.common.utils.file.FileUploadUtils;
 import com.zhongzheng.common.utils.file.FileUtils;
 import com.zhongzheng.common.utils.poi.ExcelUtil;
 import com.zhongzheng.framework.config.ServerConfig;
+import com.zhongzheng.framework.web.service.WxLoginService;
 import com.zhongzheng.modules.course.vo.CourseMenuVo;
 import com.zhongzheng.modules.goods.bo.GoodsQueryBo;
 import com.zhongzheng.modules.goods.service.IGoodsService;
@@ -25,6 +26,7 @@ import com.zhongzheng.modules.order.service.IOrderService;
 import com.zhongzheng.modules.order.service.impl.OrderServiceImpl;
 import com.zhongzheng.modules.system.service.ISysUserService;
 import com.zhongzheng.modules.user.vo.UserExportVo;
+import com.zhongzheng.modules.wx.bo.WxShareGoodsBo;
 import io.swagger.annotations.ApiOperation;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -61,6 +63,9 @@ public class CommonController
     @Autowired
     private IOrderService iOrderService;
 
+    @Autowired
+    private WxLoginService wxLoginService;
+
     /**
      * 通用下载请求
      *
@@ -194,4 +199,13 @@ public class CommonController
         iOrderService.arrangeGrade("安管继续教育网络班B类",890L,3097L,null,114L,"",174L);
         return AjaxResult.success();
     }
+
+
+    @ApiOperation("获取商品分享码")
+    @PostMapping("/shareGoodsCode")
+    public AjaxResult getWxSmallAccessToken(@RequestBody WxShareGoodsBo bo)
+    {
+        String token = wxLoginService.shareGoodsCode(bo);
+        return AjaxResult.success(token);
+    }
 }

+ 2 - 2
zhongzheng-api/src/main/java/com/zhongzheng/controller/wx/WxLoginController.java

@@ -16,6 +16,7 @@ import com.zhongzheng.modules.user.entity.ClientLoginUser;
 import com.zhongzheng.modules.user.service.IUserService;
 import com.zhongzheng.modules.user.vo.UserVo;
 import com.zhongzheng.modules.wx.bo.WxLoginBody;
+import com.zhongzheng.modules.wx.bo.WxShareGoodsBo;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -146,7 +147,7 @@ public class WxLoginController
         return AjaxResult.success(map);
     }
 
-    @ApiOperation("刷新令牌")
+    @ApiOperation("刷新登录令牌")
     @GetMapping("/refreshToken/{userAccount}")
     public AjaxResult refreshToken(@PathVariable("userAccount") String userAccount)
     {
@@ -157,5 +158,4 @@ public class WxLoginController
     }
 
 
-
 }

+ 1 - 0
zhongzheng-common/src/main/java/com/zhongzheng/common/utils/http/HttpUtils.java

@@ -143,6 +143,7 @@ public class HttpUtils
             post.addHeader("content-type", "application/json");
             HttpResponse res = client.execute(post);
             if (res.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
+                System.out.println(res.getEntity().getContent());
                 if (res.getEntity().getContentType().getValue().equalsIgnoreCase("image/jpeg")) {
                     InputStream inputStream = res.getEntity().getContent();
                     ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

+ 51 - 0
zhongzheng-framework/src/main/java/com/zhongzheng/framework/web/service/WxLoginService.java

@@ -21,6 +21,8 @@ import com.zhongzheng.common.utils.http.HttpUtils;
 import com.zhongzheng.common.utils.ip.IpUtils;
 import com.zhongzheng.modules.alisms.service.IAliSmsService;
 import com.zhongzheng.modules.course.bo.SectionWatchPerBo;
+import com.zhongzheng.modules.goods.service.IGoodsService;
+import com.zhongzheng.modules.goods.vo.GoodsVo;
 import com.zhongzheng.modules.user.bo.UserWxFollowAddBo;
 import com.zhongzheng.modules.user.domain.User;
 import com.zhongzheng.modules.user.entity.ClientLoginUser;
@@ -29,6 +31,7 @@ import com.zhongzheng.modules.user.service.IUserService;
 import com.zhongzheng.modules.user.service.IUserWxFollowService;
 import com.zhongzheng.modules.wx.bo.TemplatData;
 import com.zhongzheng.modules.wx.bo.WxLoginBody;
+import com.zhongzheng.modules.wx.bo.WxShareGoodsBo;
 import com.zhongzheng.modules.wx.service.IWxLoginService;
 import org.apache.commons.codec.binary.Base64;
 import org.slf4j.Logger;
@@ -140,6 +143,9 @@ public class WxLoginService implements IWxLoginService {
     @Autowired
     private IUserWxFollowService iUserWxFollowService;
 
+    @Autowired
+    private IGoodsService iGoodsService;
+
 
     public Map<String, String> test_login() {
         String unionId = "oQ2yp56PgQ-PfwN4vxTZhR5eTpzk";
@@ -928,6 +934,51 @@ public class WxLoginService implements IWxLoginService {
         return result;
     }
 
+    @Override
+    public String shareGoodsCode(WxShareGoodsBo bo) {
+        GoodsVo goodsVo = iGoodsService.queryById(bo.getGoodsId());
+        if(Validator.isEmpty(goodsVo)){
+            throw new CustomException("商品ID错误");
+        }
+        StringBuilder sceneParam = new StringBuilder();
+        String pageUrl = "";
+
+        String wxGzhAccessToken = getWxSmallAccessToken();
+        String param = String.format(small_wxEnCodeParam, wxGzhAccessToken);
+        String url = small_wxEnCodeUrl + "?" + param;
+        JSONObject obj = new JSONObject();
+
+        if(goodsVo.getGoodsType()==2){
+            pageUrl = "pages2/bank/detail";
+            sceneParam.append("id=").append(goodsVo.getGoodsId()).append("&");
+            sceneParam.append("sc=").append(bo.getShareCode());
+        }
+        if(goodsVo.getGoodsType()==1||goodsVo.getGoodsType()==6){
+            pageUrl = "pages3/course/detail";
+            sceneParam.append("id=").append(goodsVo.getGoodsId()).append("&");
+            sceneParam.append("goodsType=").append(goodsVo.getGoodsType()).append("&");
+            sceneParam.append("sc=").append(bo.getShareCode());
+        }
+        System.out.println(pageUrl);
+        System.out.println(sceneParam.toString());
+        obj.put("page", pageUrl);
+        obj.put("scene",sceneParam.toString());
+        obj.put("env_version",enCodeVersion);
+        String result = HttpUtils.sendPost(url, obj);
+        List<String> codes = Arrays.asList("40001", "42001");
+        JSONObject jsonObject = JSONObject.parseObject(result);
+        if(ObjectUtils.isNotNull(jsonObject.get("errcode")) && codes.contains(jsonObject.get("errcode").toString())){
+            //微信access_token 过期或者失效,刷新access_token
+            String key = "WX_SMALL_ACCESS_TOKEN";
+            redisCache.deleteObject(key);
+            String wxGzhAccessTokenTo = getWxSmallAccessToken();
+            String paramTo = String.format(small_wxEnCodeParam, wxGzhAccessTokenTo);
+            String urlTo = small_wxEnCodeUrl + "?" + paramTo;
+            return HttpUtils.sendPost(urlTo, obj);
+        }
+        return result;
+    }
+
     public Boolean subGzh(String openId) {
         String unionId = getWxGzhUserCgiInfo(openId);
         if (Validator.isNotEmpty(unionId)) {

+ 21 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/wx/bo/WxShareGoodsBo.java

@@ -0,0 +1,21 @@
+package com.zhongzheng.modules.wx.bo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.experimental.Accessors;
+
+@ApiModel("微信商品分享")
+@Data
+@NoArgsConstructor
+@Accessors(chain = true)
+public class WxShareGoodsBo {
+
+    @ApiModelProperty("商品ID")
+    private Long goodsId;
+
+
+    @ApiModelProperty("分享码")
+    private String shareCode;
+}

+ 3 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/wx/service/IWxLoginService.java

@@ -2,6 +2,7 @@ package com.zhongzheng.modules.wx.service;
 
 
 import com.zhongzheng.modules.course.bo.SectionWatchPerBo;
+import com.zhongzheng.modules.wx.bo.WxShareGoodsBo;
 
 import java.util.Map;
 
@@ -30,4 +31,6 @@ public interface IWxLoginService
 
     String getTopicEnCode(Long topicId);
 
+    String shareGoodsCode(WxShareGoodsBo bo);
+
 }