WeChat-J 更新项目删除不需要的 HTTP 客户端

This commit is contained in:
YuCheng Hu 2023-01-20 14:38:14 -05:00
parent 2037aad8a5
commit a4d7226b7b
11 changed files with 141 additions and 16 deletions

12
.idea/dataSources.xml generated Normal file
View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="0@localhost" uuid="35480a1b-ac1d-4732-bd65-fa58075ee6de">
<driver-ref>redis</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>jdbc.RedisDriver</jdbc-driver>
<jdbc-url>jdbc:redis://localhost:6379/0</jdbc-url>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
</component>
</project>

1
.idea/jpa-buddy.xml generated
View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JpaBuddyIdeaProjectConfig">
<option name="defaultUnitInitialized" value="true" />
<option name="renamerInitialized" value="true" />
</component>
</project>

7
.idea/sqldialects.xml generated Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="SqlDialectMappings">
<file url="file://$PROJECT_DIR$/src/main/resources/data.sql" dialect="H2" />
<file url="file://$PROJECT_DIR$/src/main/resources/schema.sql" dialect="H2" />
</component>
</project>

22
pom.xml
View File

@ -61,6 +61,7 @@
<scope>compile</scope>
</dependency>
<!-- SPRING -->
<dependency>
<groupId>org.springframework.boot</groupId>
@ -80,9 +81,18 @@
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<scope>provided</scope>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<!-- TEST -->
@ -104,12 +114,6 @@
</dependency>
<!--/ TEST -->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>

View File

@ -3,7 +3,7 @@ package com.ossez.wechat.demo.config;
import com.ossez.wechat.demo.common.enums.HttpClientType;
import com.ossez.wechat.demo.properties.WeChatOfficialAccountProperties;
import com.ossez.wechat.oa.api.WeChatOfficialAccountService;
import com.ossez.wechat.oa.api.impl.WeChatOfficialAccountServiceOkHttp;
import com.ossez.wechat.oa.api.impl.okhttp.WeChatOfficialAccountServiceOkHttp;
import com.ossez.wechat.oa.config.WxMpConfigStorage;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;

View File

@ -2,6 +2,8 @@ package com.ossez.wechat.demo.controller;
import com.ossez.wechat.common.exception.WxErrorException;
import com.ossez.wechat.demo.data.repository.redis.StudentRepository;
import com.ossez.wechat.demo.model.entity.Student;
import com.ossez.wechat.oa.api.WeChatOfficialAccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@ -21,10 +23,12 @@ import org.springframework.web.bind.annotation.RestController;
public class WeChatController {
private final WeChatOfficialAccountService weChatOfficialAccountService;
private final StudentRepository studentRepository;
@Autowired
public WeChatController(WeChatOfficialAccountService weChatOfficialAccountService) {
public WeChatController(WeChatOfficialAccountService weChatOfficialAccountService, StudentRepository studentRepository) {
this.weChatOfficialAccountService = weChatOfficialAccountService;
this.studentRepository = studentRepository;
}
/**
@ -37,7 +41,11 @@ public class WeChatController {
@ResponseBody
public String getAccessToken() throws WxErrorException {
return weChatOfficialAccountService.getAccessToken();
Student student = new Student(
"Eng2015001", "John Doe", Student.Gender.MALE, 1);
studentRepository.save(student);
return weChatOfficialAccountService.getAccessToken(true);
}

View File

@ -0,0 +1,9 @@
package com.ossez.wechat.demo.data.repository.redis;
import com.ossez.wechat.demo.model.entity.Student;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface StudentRepository extends CrudRepository<Student, String> {}

View File

@ -0,0 +1,62 @@
package com.ossez.wechat.demo.model.entity;
import org.springframework.data.redis.core.RedisHash;
import java.io.Serializable;
@RedisHash("Student")
public class Student implements Serializable {
public enum Gender {
MALE, FEMALE
}
private String id;
private String name;
private Gender gender;
private int grade;
public Student(String id, String name, Gender gender, int grade) {
this.id = id;
this.name = name;
this.gender = gender;
this.grade = grade;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Gender getGender() {
return gender;
}
public void setGender(Gender gender) {
this.gender = gender;
}
public int getGrade() {
return grade;
}
public void setGrade(int grade) {
this.grade = grade;
}
@Override
public String toString() {
return "Student{" + "id='" + id + '\'' + ", name='" + name + '\'' + ", gender=" + gender + ", grade=" + grade + '}';
}
}

View File

@ -10,10 +10,18 @@ spring.jpa.show-sql=false
spring.jpa.hibernate.ddl-auto=none
spring.jpa.hibernate.use-new-id-generator-mappings=false
spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
spring.datasource.url=
spring.datasource.username=
spring.datasource.password=
#spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
#spring.datasource.url=
#spring.datasource.username=
#spring.datasource.password=
spring.datasource.url=jdbc:h2:mem:test
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=password
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.h2.console.enabled=true
spring.h2.console.path=/h2-console
spring.datasource.hikari.connection-timeout=50000
spring.datasource.hikari.idle-timeout=300000
@ -34,6 +42,10 @@ spring.datasource.hikari.data-source-properties.cacheServerConfiguration=true
spring.datasource.hikari.data-source-properties.elideSetAutoCommits=true
spring.datasource.hikari.data-source-properties.maintainTimeStats=false
# REDIS
spring.redis.host=localhost
spring.redis.port=6379
# KEY
wechat.official-account.app-id = wx637b82a7f94123ef
wechat.official-account.secret = 343cecbc44d69e45367a65cc9b4d3925

View File

@ -0,0 +1,3 @@
INSERT INTO CITY VALUES (11, 'Delhi', 110001);
INSERT INTO CITY VALUES (12, 'Kanpur', 208001);
INSERT INTO CITY VALUES (13, 'Lucknow', 226001);

View File

@ -0,0 +1,7 @@
DROP TABLE IF EXISTS CITY;
CREATE TABLE CITY
(
city_code INT AUTO_INCREMENT PRIMARY KEY,
city_name VARCHAR NOT NULL,
city_pincode INT NOT NULL
);