直接上自己最后成功的代码
WxShareController .java
其中JSConfig方法前端报错,后自行让前端传url,改成JSConfig1方法便完美了
package com.youruan.education.controller;
import com.youruan.education.config.global.Constant;
import com.youruan.education.config.model.ResultData;
import com.youruan.education.service.WxShareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
@RestController
@RequestMapping
public class WxShareController {
@Autowired
private WxShareService wxShareService;
/**
* 前端 参数获取
* @return
*/
@GetMapping("share")
public ResultData share(String url) throws Exception {
return ResultData.ok200().setData(wxShareService.share(url)).setMessage(Constant.QUERY_SUCCESS);
}
}
WxShareService
package com.youruan.education.service;
import com.youruan.education.entity.WxShare;
import javax.servlet.http.HttpServletRequest;
public interface WxShareService {
WxShare share(String url) throws Exception;
}
WxShareServiceImpl
package com.youruan.education.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.youruan.education.config.excetion.ServiceException;
import com.youruan.education.config.global.Mark;
import com.youruan.education.entity.WxShare;
import com.youruan.education.service.BrowserHisService;
import com.youruan.education.service.WxShareService;
import com.youruan.education.util.CommonUtil;
import com.youruan.education.util.GZHUtil;
import com.youruan.education.util.HttpUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
@Service
@Transactional