| | |
| | | /* |
| | | package com.ruoyi.member.controller; |
| | | |
| | | import java.io.BufferedReader; |
| | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.crypto.Cipher; |
| | | import javax.crypto.spec.IvParameterSpec; |
| | | import javax.crypto.spec.SecretKeySpec; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | | import cn.binarywang.wx.miniapp.api.WxMaService; |
| | | import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.common.core.utils.sign.Base64; |
| | | import com.ruoyi.system.api.domain.AppMiniLoginVO; |
| | | import com.ruoyi.system.api.domain.dto.AppMiniLoginDTO; |
| | | import com.ruoyi.member.util.*; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.stereotype.Controller; |
| | | 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.ResponseBody; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | |
| | | |
| | | import net.sf.json.JSON; |
| | | |
| | | import org.bouncycastle.jce.provider.BouncyCastleProvider; |
| | | |
| | | */ |
| | | /** |
| | | * 微信授权方面 |
| | | * |
| | | * @author tuzx |
| | | * @date 2018年8月9日 |
| | | * @version 1.0 |
| | | */ |
| | | *//* |
| | | |
| | | @Controller |
| | | @RequestMapping("/weixin") |
| | | public class WeiXinAppController { |
| | | |
| | | private static String appid = "wx0e4769839d84fde0"; |
| | | private static String appSecret = "ede69db0303ddde49b5db95f186918ec"; |
| | | |
| | | @Resource |
| | | private WxMaService wxMaService; |
| | | |
| | | @RequestMapping("/getAddress") |
| | | @ResponseBody |
| | |
| | | } |
| | | |
| | | @ResponseBody |
| | | @RequestMapping("/getOpenId") |
| | | @ApiOperation(value = "获取微信的OpenId") |
| | | public R<Map<String, String>> getOpenId(String code) { |
| | | @PostMapping("/miniLogin") |
| | | @ApiOperation("小程序登录") |
| | | public R<AppMiniLoginVO> getMemberByCode(@RequestBody AppMiniLoginDTO appMiniLoginDto) |
| | | { |
| | | AppMiniLoginVO appMiniLoginVo = new AppMiniLoginVO(); |
| | | WxMaJscode2SessionResult session = null; |
| | | String unionid; |
| | | String openid; |
| | | String sessionKey = null; |
| | | //获取session |
| | | try { |
| | | String openID = JsapiTicketUtil.getOpenId(code); |
| | | Map<String,String> data=new HashMap<>(); |
| | | data.put("openID",openID); |
| | | return R.ok(data); |
| | | session = wxMaService.getUserService().getSessionInfo(appMiniLoginDto.getCode()); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return null; |
| | | } |
| | | return R.fail("获取异常"); |
| | | if (session != null && StringUtils.isNotBlank(session.getOpenid())) { |
| | | unionid = session.getUnionid(); |
| | | openid = session.getOpenid(); |
| | | sessionKey = session.getSessionKey(); |
| | | |
| | | appMiniLoginVo.setMiniOpenid(openid); |
| | | appMiniLoginVo.setWxUnionid(unionid); |
| | | appMiniLoginVo.setSessionKey(sessionKey); |
| | | } |
| | | |
| | | if(appMiniLoginVo ==null){ |
| | | return R.fail("登录失败!"); |
| | | } |
| | | return R.ok(appMiniLoginVo); |
| | | } |
| | | |
| | | @ResponseBody |
| | |
| | | return R.fail("获取异常"); |
| | | } |
| | | |
| | | /** |
| | | */ |
| | | /** |
| | | * 获取微信用户信息 |
| | | * |
| | | * @param token |
| | | * @param openid |
| | | * @return |
| | | */ |
| | | *//* |
| | | |
| | | @ResponseBody |
| | | @RequestMapping("/getWXinfo") |
| | | @ApiOperation(value = "获取微信用户信息") |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | */ |
| | | /** |
| | | * 小程序使用jscode获取openid |
| | | * @param jscode |
| | | * @return |
| | | *//* |
| | | */ |
| | | /* |
| | | public String code2Session(String jscode){ |
| | | String url = "https://api.weixin.qq.com/sns/jscode2session?appid=" + appid + "&secret=" + appSecret |
| | | + "&js_code=" + jscode + "&grant_type=authorization_code"; |
| | |
| | | return jsonObject.getString("errmsg"); |
| | | } |
| | | return null; |
| | | }*/ |
| | | }*//* |
| | | |
| | | /*** |
| | | |
| | | */ |
| | | /*** |
| | | * 模拟get请求 |
| | | * |
| | | * @param url |
| | | * @param charset |
| | | * @param timeout |
| | | * @return |
| | | */ |
| | | *//* |
| | | |
| | | public static String sendGet(String url, String charset, int timeout) { |
| | | String result = ""; |
| | | try { |
| | |
| | | return null; |
| | | } |
| | | } |
| | | */ |