| | |
| | | |
| | | |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.http.HttpEntity; |
| | | import org.springframework.http.HttpHeaders; |
| | | import org.springframework.http.HttpMethod; |
| | | |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.client.RestClientException; |
| | | |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | import java.util.HashMap; |
| | |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.moral.api.service.UserLogService; |
| | | |
| | | |
| | | public class WechatUtils { |
| | | |
| | |
| | | |
| | | return jsonObject; |
| | | } |
| | | |
| | | public static String getAccessToken() { |
| | | RestTemplate restTemplate = new RestTemplate(); |
| | | Map<String, String> params = new HashMap<>(); |
| | | params.put("APPID", APPID); // |
| | | params.put("APPSECRET", SECRET); // |
| | | ResponseEntity<String> responseEntity = restTemplate.getForEntity( |
| | | "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={APPID}&secret={APPSECRET}", String.class, params); |
| | | String body = responseEntity.getBody(); |
| | | JSONObject object = JSON.parseObject(body); |
| | | String Access_Token = object.getString("access_token"); |
| | | // String expires_in = object.getString("expires_in"); |
| | | return Access_Token; |
| | | } |
| | | } |