1
0
fushengqian 1 жил өмнө
parent
commit
d7b8e9d537

+ 9 - 0
fuint-application/src/main/java/com/fuint/common/service/WeixinService.java

@@ -175,4 +175,13 @@ public interface WeixinService {
      * */
     Boolean isOpenCard(Integer merchantId, String cardId, String openId);
 
+    /**
+     * 生成小程序链接
+     *
+     * @param merchantId 商户ID
+     * @param path 页面路径
+     * @return
+     * */
+    String createMiniAppLink(Integer merchantId, String path);
+
 }

+ 39 - 0
fuint-application/src/main/java/com/fuint/common/service/impl/WeixinServiceImpl.java

@@ -904,6 +904,45 @@ public class WeixinServiceImpl implements WeixinService {
         return true;
     }
 
+    /**
+     * 生成小程序链接
+     *
+     * @param merchantId 商户ID
+     * @param path 页面路径
+     * @return
+     * */
+    @Override
+    public String createMiniAppLink(Integer merchantId, String path) {
+        String link = "";
+        try {
+            String accessToken = getAccessToken(merchantId, true,true);
+            if (StringUtil.isEmpty(accessToken)) {
+                return "";
+            }
+            String url = "https://api.weixin.qq.com/wxa/genwxashortlink?access_token=" + accessToken +"&";
+
+            Map<String, Object> param = new HashMap<>();
+            param.put("page_url", path);
+
+            String reqDataJsonStr = JsonUtil.toJSONString(param);
+            String response = HttpRESTDataClient.requestPostBody(url, reqDataJsonStr);
+            logger.info("微信生成链接接口返回:{}", response);
+            JSONObject data = (JSONObject) JSONObject.parse(response);
+
+            if (data.get("errcode").toString().equals("0")) {
+                Object linkObject = data.get("link");
+                if (linkObject != null && StringUtil.isNotEmpty(linkObject.toString())) {
+                    link = linkObject.toString();
+                }
+            }
+        } catch (Exception e) {
+            logger.error("微信生成链接接口出错:{}", e.getMessage());
+            return "";
+        }
+
+        return link;
+    }
+
     /**
      * 刷卡支付
      *

+ 59 - 5
fuint-application/src/main/java/com/fuint/module/clientApi/controller/ClientShareController.java

@@ -6,17 +6,22 @@ import com.fuint.common.dto.UserInfo;
 import com.fuint.common.enums.StatusEnum;
 import com.fuint.common.param.ShareListParam;
 import com.fuint.common.service.CommissionRelationService;
+import com.fuint.common.service.MemberService;
+import com.fuint.common.service.MerchantService;
+import com.fuint.common.service.WeixinService;
 import com.fuint.common.util.TokenUtil;
 import com.fuint.framework.exception.BusinessCheckException;
 import com.fuint.framework.pagination.PaginationRequest;
 import com.fuint.framework.pagination.PaginationResponse;
 import com.fuint.framework.web.BaseController;
 import com.fuint.framework.web.ResponseObject;
+import com.fuint.repository.model.MtUser;
 import com.fuint.utils.StringUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.AllArgsConstructor;
 import java.lang.reflect.InvocationTargetException;
+import org.springframework.core.env.Environment;
 import org.springframework.web.bind.annotation.*;
 import javax.servlet.http.HttpServletRequest;
 import java.util.HashMap;
@@ -34,11 +39,28 @@ import java.util.Map;
 @RequestMapping(value = "/clientApi/share")
 public class ClientShareController extends BaseController {
 
+    private Environment env;
+
     /**
      * 分佣提成关系服务接口
      * */
     private CommissionRelationService commissionRelationService;
 
+    /**
+     * 微信相关服务接口
+     * */
+    private WeixinService weixinService;
+
+    /**
+     * 商户服务接口
+     */
+    private MerchantService merchantService;
+
+    /**
+     * 会员服务接口
+     * */
+    private MemberService memberService;
+
     /**
      * 获取邀请列表
      */
@@ -74,12 +96,44 @@ public class ClientShareController extends BaseController {
         PaginationResponse<CommissionRelationDto> paginationResponse = commissionRelationService.queryRelationByPagination(paginationRequest);
 
         Map<String, Object> outParams = new HashMap();
-        outParams.put("content", paginationResponse.getContent());
-        outParams.put("pageSize", paginationResponse.getPageSize());
-        outParams.put("pageNumber", paginationResponse.getCurrentPage());
-        outParams.put("totalRow", paginationResponse.getTotalElements());
-        outParams.put("totalPage", paginationResponse.getTotalPages());
+        String url = env.getProperty("website.url");
+        outParams.put("url", url);
+        outParams.put("paginationResponse", paginationResponse);
 
         return getSuccessResult(outParams);
     }
+
+    /**
+     * 生成小程序链接
+     */
+    @ApiOperation(value = "生成小程序链接")
+    @RequestMapping(value = "/getMiniAppLink", method = RequestMethod.POST)
+    @CrossOrigin
+    public ResponseObject getMiniAppLink(HttpServletRequest request, @RequestBody Map<String, Object> param) throws BusinessCheckException {
+        String token = request.getHeader("Access-Token");
+        String merchantNo = request.getHeader("merchantNo") == null ? "" : request.getHeader("merchantNo");
+        UserInfo mtUser = TokenUtil.getUserInfoByToken(token);
+        if (null == mtUser) {
+            return getFailureResult(1001);
+        }
+
+        String path = param.get("path") == null ? "" : param.get("path").toString();
+        String query = param.get("query") == null ? "" : param.get("query").toString();
+        Integer merchantId = merchantService.getMerchantId(merchantNo);
+
+        if (merchantId == null || merchantId <= 0) {
+            MtUser userInfo = memberService.queryMemberById(mtUser.getId());
+            if (userInfo != null) {
+                merchantId = userInfo.getMerchantId();
+            }
+        }
+
+        String link = weixinService.createMiniAppLink(merchantId, path + query);
+
+        Map<String, Object> outParams = new HashMap();
+        outParams.put("link", link);
+
+        ResponseObject responseObject = getSuccessResult(outParams);
+        return getSuccessResult(responseObject.getData());
+    }
 }