微信公众号 自定义分享功能

直接上自己最后成功的代码

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值