1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- package com.hz.employmentsite.controller;
- import com.hz.employmentsite.filter.exception.BaseResponse;
- import com.hz.employmentsite.filter.exception.RespGenerstor;
- import com.hz.employmentsite.services.service.WechatService;
- import me.chanjar.weixin.common.error.WxErrorException;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.PostMapping;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RestController;
- import java.util.HashMap;
- import java.util.Map;
- @RestController
- @RequestMapping("/api/wx")
- public class WxController {
- /*@Autowired
- private RemoteHelper remoteHelper;
- @GetMapping("/getWxToken")
- public String getWxToken() {
- Map<String, String> params = new HashMap<>();
- params.put("grant_type","client_credential");
- params.put("appid","wx765e6ec59e26c288");
- params.put("secret","a44d8034671866e957484f5ed4e1df48");
- remoteHelper.getJson(params, "https://api.weixin.qq.com/cgi-bin/token",null);
- return "";
- }*/
- @Autowired
- private WechatService wechatService;
- @GetMapping("getOAuthUrl")
- public BaseResponse<String> getOAuthUrl() {
- return RespGenerstor.success(wechatService.getOAuthUrl(""));
- }
- @GetMapping("getOpenId")
- public BaseResponse<String> getOpenId(String code) throws WxErrorException {
- return RespGenerstor.success(wechatService.getOpenId(code));
- }
- @PostMapping("/sentMsg")
- public BaseResponse<String> sentMsg(){
- Map<String,String> data = new HashMap<>();
- data.put("keyword1","巧克力");
- data.put("keyword2","39.8元");
- data.put("keyword3","2014年9月22日");
- return RespGenerstor.success(wechatService.sentMsg("admin",data));
- }
- }
|