| | |
| | | package com.kidgrow.oprationcenter.controller.weixin; |
| | | |
| | | import cn.hutool.http.HttpUtil; |
| | | import com.kidgrow.common.model.ResultBody; |
| | | import com.kidgrow.common.utils.QRCodeUtil; |
| | | import com.kidgrow.common.utils.StringUtils; |
| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.collections.MapUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | |
| | | WeiXinOfficPayProperties weiXinOfficPayProperties; |
| | | @Autowired |
| | | WxService wxService; |
| | | @Value("${wechat.miniapp.appid}") |
| | | private String APPID; |
| | | @Value("${wechat.miniapp.secret}") |
| | | private String SECRET; |
| | | @Value("${wechat.apiUrl}") |
| | | private String APIURL; |
| | | |
| | | /** |
| | | * 测试微信的预支付接口 |
| | |
| | | return callback; |
| | | } |
| | | |
| | | /** |
| | | * 公众号或者小程序获取 openid |
| | | * @param code |
| | | * @return |
| | | */ |
| | | @GetMapping("/getOpenId") |
| | | public ResultBody getOpenId(@RequestParam("code")String code){ |
| | | if (StringUtils.isBlank(code)) { |
| | | return ResultBody.failed("请输入code"); |
| | | } |
| | | Map<String,Object> map=new HashMap<>(); |
| | | map.put("appid",APPID); |
| | | map.put("secret",SECRET); |
| | | map.put("js_code",code); |
| | | map.put("grant_type","authorization_code"); |
| | | String s = HttpUtil.get(APIURL + "/sns/jscode2session?", map); |
| | | return ResultBody.ok().data(s); |
| | | } |
| | | |
| | | |
| | | public static void main(String[] args) throws Exception { |
| | | WxController weixinController=new WxController(); |
| | | Map<String,Object> map=null; |