分享微信推送早安代码

先在微信公众平台设置好模板和测试号:

地址:微信公众平台

下面是我的模板:

{
  {riqi.DATA}} {
  {beizhu.DATA}} 
地区:{
  {districtName.DATA}}
天气:{
  {tianqi.DATA}} 
风级:{
  {windclass.DATA}} 
风向:{
  {winddir.DATA}} 
最低气温: {
  {low.DATA}}度 
最高气温: {
  {high.DATA}}度 

今天是我们恋爱的第{
  {lianai.DATA}}天 
距离{
  {you.DATA}}生日还有{
  {shengri1.DATA}}天
距离{
  {me.DATA}}生日还有{
  {shengri2.DATA}}天

{
  {lubarmonth.DATA}} {
  {lunarday.DATA}} 
宜:{
  {fitness.DATA}} 
不宜:{
  {taboo.DATA}} 

星座指数:{
  {zhishu.DATA}} 
{
  {content.DATA}} 

{
  {caihongpi.DATA}} 

{
  {qingshi.DATA}} 

{
  {en.DATA}} 
{
  {zh.DATA}} 

然后我们来到项目代码部分,项目使用springboot框架,使用前先导入依赖:


    <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.18.20</version>
        <scope>provided</scope>
    </dependency>

    <!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>fastjson</artifactId>
        <version>2.0.7</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.junit.vintage</groupId>
                <artifactId>junit-vintage-engine</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.github.binarywang/weixin-java-mp -->
    <dependency>
        <groupId>com.github.binarywang</groupId>
        <artifactId>weixin-java-mp</artifactId>
        <version>3.3.0</version>
    </dependency>

1、天行数据接口,第三方接口用于接入彩虹屁、黄历、情诗等,

地址:天行数据TianAPI - 开发者API数据平台

public class CaiHongPiUtils {
	
    public static String getCaiHongPi(String key) {
        String httpUrl = "http://api.tianapi.com/caihongpi/index?key="+key;
        BufferedReader reader = null;
        String result = null;
        StringBuffer sbf = new StringBuffer();

        try {
            URL url = new URL(httpUrl);
            HttpURLConnection connection = (HttpURLConnection) url
                    .openConnection();
            connection.setRequestMethod("GET");
            InputStream is = connection.getInputStream();
            reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
            String strRead = null;
            while ((strRead = reader.readLine()) != null) {
                sbf.append(strRead);
                sbf.append("\r\n");
            }
            reader.close();
            result = sbf.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        JSONObject jsonObject = JSONObject.parseObject(result);
        JSONArray newslist = jsonObject.getJSONArray("newslist");
        String content = newslist.getJSONObject(0).getString("content");
        return content;
    }

    public static Map<String,String> getEveryday(String key) {
        String httpUrl = "http://api.tianapi.com/everyday/index?key="+key;
        BufferedReader reader = null;
        String result = null;
        StringBuffer sbf = new StringBuffer();
        try {
            URL url = new URL(httpUrl);
            HttpURLConnection connection = (HttpURLConnection) url
                    .openConnection();
            connection.setRequestMethod("GET");
            InputStream is = connection.getInputStream();
            reader = new BufferedReader(new InputStreamReader(is, "UTF-8
  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值