WechatHelp.java 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package com.qxgmat.help;
  2. import com.nuliji.tools.third.OauthData;
  3. import com.nuliji.tools.third.wechat.MessageListener;
  4. import com.nuliji.tools.third.wechat.WechatClient;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.beans.factory.annotation.Value;
  7. import org.springframework.stereotype.Service;
  8. @Service
  9. public class WechatHelp {
  10. private WechatClient wechatPc;
  11. @Autowired
  12. private void getWechatPc(@Value("${third.wechat.pc.appId}") String appId,
  13. @Value("${third.wechat.pc.appSecret}") String appSecret) {
  14. this.wechatPc = new WechatClient(appId, appSecret);
  15. }
  16. private WechatClient wechat;
  17. @Autowired
  18. private void getWechat(@Value("${third.wechat.native.appId}") String appId,
  19. @Value("${third.wechat.native.appSecret}") String appSecret) {
  20. this.wechat = new WechatClient(appId, appSecret);
  21. }
  22. public OauthData oauthPc(String code) {
  23. return wechatPc.webAuthorize(code);
  24. }
  25. public OauthData oauthNative(String code){
  26. return wechat.webAuthorize(code);
  27. }
  28. public OauthData refreshNative(String refreshToken) {
  29. return wechat.refreshWebAccessToken(refreshToken);
  30. }
  31. public String redirectPc(String redirectUrl, String state){
  32. return wechatPc.getOAuthUrl(redirectUrl, state);
  33. }
  34. public String redirectNative(String redirectUrl, String state){
  35. return wechat.getOAuthUrl(redirectUrl, state);
  36. }
  37. public String receiveMessage(String body){
  38. wechat.ReceiveMessage(body, new MessageListener() {
  39. @Override
  40. public void OnScan(String openId, int sceneId) {
  41. }
  42. @Override
  43. public void OnSubscribe(String openId) {
  44. }
  45. });
  46. return "";
  47. }
  48. }