Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
binarywang committed Jun 10, 2017
1 parent 830689e commit dee9994
Show file tree
Hide file tree
Showing 29 changed files with 617 additions and 505 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
/.settings/
*.project
*.classpath
application.properties
application.yml
/.idea/
*.iml
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: java
jdk:
- oraclejdk8

script: "mvn clean package -Dmaven.test.skip=true"

branches:
only:
- master

notifications:
email:
- binaryw@qq.com
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
### 本Demo基于Spring Boot构建,实现微信公众号开发功能。
### 本项目为weixin-java-tools的Demo演示程序,更多Demo请查阅:https://github.com/Wechat-Group/weixin-java-tools

[![Build Status](https://travis-ci.org/Wechat-Group/weixin-java-mp-demo-springboot.svg?branch=master)](https://travis-ci.org/Wechat-Group/weixin-java-mp-demo-springboot)
-----------------------

## 使用步骤:
1. 配置:复制`/src/main/resources/application.yml.template` 生成application.yml文件,根据自己需要填写相关配置(需要注意的是:yml文件内的属性冒号后面的文字之前需要加空格,可参考已有配置,否则属性会设置不成功);
1. 运行Java程序:`com.github.binarywang.demo.wechat.WxMpDemoApplication`
1. 打开shell或cmd,进入ngrok目录,运行 `ngrok -config ngrok.cfg -subdomain my-domain 8080` 如果运行失败,请更换my-domain为其它字符串,直至连接成功;
1. 配置微信公众号中的接口地址:http://my-domain.tunnel.qydev.com/wechat/portal (注意my-domain要跟上面的一致,需要符合微信官方的要求);
1. 根据自己需要修改各个handler的实现,加入自己的业务逻辑。

3 changes: 3 additions & 0 deletions ngrok/ngrok.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
server_addr: "tunnel.qydev.com:4443"
trust_host_root_certs: false

Binary file added ngrok/ngrok.exe
Binary file not shown.
43 changes: 14 additions & 29 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,22 @@
<version>1.4.1.RELEASE</version>
</parent>

<groupId>com.github.binarywang.wechat</groupId>
<groupId>com.github.binarywang</groupId>
<version>1.0.0-SNAPSHOT</version>
<artifactId>weixin-mp-demo-springboot</artifactId>
<artifactId>weixin-java-mp-demo-springboot</artifactId>
<packaging>jar</packaging>

<name>spring-boot-demo-for-wechat-mp</name>
<description>Spring Boot Demo with wechat MP</description>

<properties>
<weixin-java-mp.version>2.6.2.BETA</weixin-java-mp.version>

<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.locales>zh_CN</project.build.locales>
<project.build.jdk>1.7</project.build.jdk>
<weixin-java-mp.version>2.2.4</weixin-java-mp.version>
</properties>

<dependencies>
Expand All @@ -44,32 +47,14 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${project.build.jdk}</source>
<target>${project.build.jdk}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<groups>com.testwithspring.starter.springboot.UnitTest</groups>
</configuration>
</plugin>
</plugins>
</build>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com.github.binarywang.demo.wechat;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
*
* @author Binary Wang
*/
@SpringBootApplication
public class WechatMpDemoApplication {

public static void main(String[] args) {
SpringApplication.run(WechatMpDemoApplication.class, args);
}
}
package com.github.binarywang.demo.wechat;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
* @author Binary Wang(https://github.com/binarywang)
*/
@SpringBootApplication
public class WxMpDemoApplication {

public static void main(String[] args) {
SpringApplication.run(WxMpDemoApplication.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
package com.github.binarywang.demo.wechat.builder;

import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;

/**
*
* @author Binary Wang
*
* @author Binary Wang(https://github.com/binarywang)
*/
public abstract class AbstractBuilder {
protected final Logger logger = LoggerFactory.getLogger(getClass());
protected final Logger logger = LoggerFactory.getLogger(getClass());

public abstract WxMpXmlOutMessage build(String content,
WxMpXmlMessage wxMessage, WxMpService service);
public abstract WxMpXmlOutMessage build(String content,
WxMpXmlMessage wxMessage, WxMpService service);
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
package com.github.binarywang.demo.wechat.builder;

import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.WxMpXmlOutImageMessage;
import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutImageMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;

/**
*
* @author Binary Wang
*
* @author Binary Wang(https://github.com/binarywang)
*/
public class ImageBuilder extends AbstractBuilder {

@Override
public WxMpXmlOutMessage build(String content, WxMpXmlMessage wxMessage,
WxMpService service) {
@Override
public WxMpXmlOutMessage build(String content, WxMpXmlMessage wxMessage,
WxMpService service) {

WxMpXmlOutImageMessage m = WxMpXmlOutMessage.IMAGE().mediaId(content)
.fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser())
.build();
WxMpXmlOutImageMessage m = WxMpXmlOutMessage.IMAGE().mediaId(content)
.fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser())
.build();

return m;
}
return m;
}

}
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
package com.github.binarywang.demo.wechat.builder;

import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;
import me.chanjar.weixin.mp.bean.WxMpXmlOutTextMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutTextMessage;

/**
*
* @author Binary Wang
*
* @author Binary Wang(https://github.com/binarywang)
*/
public class TextBuilder extends AbstractBuilder {

@Override
public WxMpXmlOutMessage build(String content, WxMpXmlMessage wxMessage,
WxMpService service) {
WxMpXmlOutTextMessage m = WxMpXmlOutMessage.TEXT().content(content)
.fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser())
.build();
return m;
}
@Override
public WxMpXmlOutMessage build(String content, WxMpXmlMessage wxMessage,
WxMpService service) {
WxMpXmlOutTextMessage m = WxMpXmlOutMessage.TEXT().content(content)
.fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser())
.build();
return m;
}

}
Loading

0 comments on commit dee9994

Please sign in to comment.