关于微信接口调用

闲着没事  写个关于微信接口调用的吧

1.先去公众号设置ip白名单

配置白名单建议配置3个ip(外网Ip需要配置 内网不需要)

公司ip

ipconfig后的本地ip

线上ip

本地调试

2.拿到appid和appsecret 而且要注意的是 appsecret他会且只会告诉你一次 一定要存起来 否则就得重置了

3.通过appid和appsecret取得access_token 这是微信返回给你的 每次都会变

遇到问题

a)hibernate生成表明全是小写

解决办法

设置一下hibernate表名生成策略 让他按照你注解里边写的名生成

spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

b)http请求一直报400

对象传递改为参数传递(现在只是缓解 有待彻底解决)

c)跨机器 可以垮ip访问就是可以夸服务器访问 所以定时调度部署在哪台机器上都行

一个关于两个主键的错 两种解决方案

1.反正开始那个表已经生成了 去掉一个主键

2.加上@IdClass 个人不建议这个 后续还会出现其他bug

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'startRule': Unsatisfied dependency expressed through field 'ruleRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ruleRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: This class [class com.alert.alertSmas.entity.AlertRule] does not define an IdClass
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
	at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
	at com.alert.alertSmas.AlertSmasApplication.main(AlertSmasApplication.java:21) [classes/:na]

 

这个

工程的注入 不是通过注解 而是通过配置xml文件的 所谓依赖注入吧

api.xml

server.xml

微信接口返回

如果是失败 每个errcode也都有自己的含义 比如下边这个是没配置ip白名单{"errcode":40164,"errmsg":"invalid ip ***.***.***.96, not in whitelist hint: [CX6iSa07763187]"}

成功

{"errcode":0,"errmsg":"ok","msgid":91351397420810240}

微信返回给我们的Json要和实体一一对应 不然会报Json转换失败的错 可以在映射实体上加上

import org.codehaus.jackson.annotate.JsonIgnoreProperties;

@JsonIgnoreProperties(ignoreUnknown = true)//忽略不具备的属性

访问微信接口时 用的是外网ip 内网的不认 所以要配置外网ip白名单

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您好!关于使用 FeignClient 调用微信接口,我可以为您提供一些基本的指导。请注意,以下是一般步骤,具体的代码实现可能会因您的项目需求和微信接口的具体要求而有所不同。 1. 添加 FeignClient 依赖:在您的项目的 pom.xml 文件中,添加 FeignClient 的依赖。示例: ```xml <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> </dependency> ``` 2. 创建 FeignClient 接口:在您的项目中创建一个 FeignClient 接口,用于定义微信接口调用方法。示例: ```java @FeignClient(name = "weixin-client", url = "https://api.weixin.qq.com") public interface WeixinClient { @GetMapping("/user/info") UserInfo getUserInfo(@RequestParam("userId") String userId); } ``` 请根据实际情况修改 `WeixinClient` 接口上的 `name` 和 `url` 属性,并定义适合您项目的方法和参数。 3. 配置 FeignClient:在您的项目配置文件中,添加 FeignClient 的相关配置。示例: ```yaml spring: application: name: your-application-name ``` 请将 `your-application-name` 替换为您的应用程序名称。 4. 使用 FeignClient 调用微信接口:在需要调用微信接口的地方,注入 `WeixinClient` 接口,并调用相应的方法。示例: ```java @RestController public class UserController { private final WeixinClient weixinClient; public UserController(WeixinClient weixinClient) { this.weixinClient = weixinClient; } @GetMapping("/user/{userId}") public UserInfo getUser(@PathVariable String userId) { return weixinClient.getUserInfo(userId); } } ``` 请根据实际情况修改 `UserController` 类和相应的方法。 这里只是一个简单的示例,具体的实现方式可能会因您的项目架构和微信接口的复杂性而有所不同。您需要根据实际情况进行适配和修改。希望对您有所帮助!如需进一步的帮助,请提供更多详细的信息。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值