| | |
| | | |
| | | import cn.binarywang.wx.miniapp.api.WxMaService; |
| | | import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.alibaba.fastjson.TypeReference; |
| | | import com.alibaba.fastjson.parser.Feature; |
| | | import com.alipay.api.AlipayApiException; |
| | | import com.alipay.api.AlipayClient; |
| | | import com.alipay.api.DefaultAlipayClient; |
| | | import com.alipay.api.internal.util.AlipayEncrypt; |
| | | import com.alipay.api.internal.util.AlipaySignature; |
| | | import com.alipay.api.request.AlipaySystemOauthTokenRequest; |
| | | import com.alipay.api.request.AlipayUserInfoShareRequest; |
| | | import com.alipay.api.response.AlipaySystemOauthTokenResponse; |
| | |
| | | throw new ServiceException("密码输入错误"); |
| | | } |
| | | |
| | | if (!sysUser.getUserType().equals("2")){ |
| | | throw new ServiceException("该人员不是拍卖师"); |
| | | } |
| | | |
| | | LambdaQueryWrapper<AuctionSalesroom> wrapper=Wrappers.lambdaQuery(); |
| | | wrapper.eq(AuctionSalesroom::getAuctionSalesroomNo,arepartAuctionBidRecordDTO.getAuctionSalesroomQrcode()); |
| | | wrapper.eq(AuctionSalesroom::getDelFlag,0); |
| | |
| | | |
| | | @Override |
| | | public AppMiniLoginVO actionMiniLogin(AppMiniLoginDTO appMiniLoginDto) { |
| | | try { |
| | | AppMiniLoginVO appMiniLoginVo = new AppMiniLoginVO(); |
| | | if (appMiniLoginDto.getType()==1){ |
| | | if (appMiniLoginDto.getAuth_code()== null || appMiniLoginDto.getAuth_code().length() == 0) { |
| | | if (appMiniLoginDto.getType()==1) { |
| | | if (appMiniLoginDto.getAuth_code() == null || appMiniLoginDto.getAuth_code().length() == 0) { |
| | | } else { |
| | | AppMiniLoginVO user=new AppMiniLoginVO(); |
| | | /* AppMiniLoginVO user=new AppMiniLoginVO(); |
| | | //String serverUrl, String appId, String privateKey, String format,String charset, String alipayPublicKey, String signType |
| | | //实例化客户端 参数:正式环境URL,Appid,商户私钥 PKCS8格式,字符编码格式,字符格式,支付宝公钥,签名方式 |
| | | AlipayClient alipayClient = new DefaultAlipayClient(ALIPAY_BORDER_PROD,APP_ID_PROD, APP_PRIVATE_KEY, "json", "GBK", ALIPAY_PUBLIC_KEY, "RSA2"); |
| | |
| | | throw new RuntimeException(e); |
| | | } |
| | | //刷新令牌,上次换取访问令牌时得到。见出参的refresh_token字段 |
| | | request.setRefreshToken(response.getAccessToken()); |
| | | |
| | | //返回成功时 就将唯一标识返回 |
| | | if (response.isSuccess()) { |
| | |
| | | //我这里只返回了一个字段给前端用 |
| | | String user1= response.getOpenId(); |
| | | appMiniLoginVo.setZfbuserid(response.getOpenId()); |
| | | AlipayUserInfoShareResponse alipayUserInfoShareResponse=getAliUserInfo(response.getAccessToken()); |
| | | appMiniLoginVo.setPhone(alipayUserInfoShareResponse.getPhone()); |
| | | AlipayUserInfoShareResponse alipayUserInfoShareResponse= null; |
| | | try { |
| | | AlipayUserInfoShareRequest request1 = new AlipayUserInfoShareRequest(); |
| | | AlipayUserInfoShareResponse response1 = alipayClient.execute(request1, response.getAccessToken()); |
| | | appMiniLoginVo.setPhone(response1.getPhone()); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | |
| | | R<SysUser> sysUserR = sysUserClient.queryUserByPhone(alipayUserInfoShareResponse.getPhone()); |
| | | SysUser data = sysUserR.getData(); |
| | | appMiniLoginVo.setSysUser(data); |
| | | } |
| | | }*/ |
| | | |
| | | |
| | | String response = JSON.parseObject(appMiniLoginDto.getAuth_code()).getString("response"); |
| | | |
| | | //1. 获取验签和解密所需要的参数 |
| | | Map<String, String> openapiResult = JSON.parseObject(appMiniLoginDto.getAuth_code(), |
| | | new TypeReference<Map<String, String>>() { |
| | | }, Feature.OrderedField); |
| | | String signType = "RSA2"; |
| | | String charset = "UTF-8"; |
| | | String encryptType = "AES"; |
| | | String sign = openapiResult.get("sign"); |
| | | String content = openapiResult.get("response"); |
| | | |
| | | //如果密文的 |
| | | boolean isDataEncrypted = !content.startsWith("{"); |
| | | boolean signCheckPass = false; |
| | | |
| | | //2. 验签 |
| | | String signContent = content; |
| | | |
| | | //如果是加密的报文则需要在密文的前后添加双引号 |
| | | if (isDataEncrypted) { |
| | | signContent = "\"" + signContent + "\""; |
| | | } |
| | | try { |
| | | signCheckPass = AlipaySignature.rsaCheck(signContent, sign, ALIPAY_PUBLIC_KEY, charset, signType); |
| | | } catch (AlipayApiException e) { |
| | | //验签异常, 日志 |
| | | } |
| | | if (!signCheckPass) { |
| | | //验签不通过(异常或者报文被篡改),终止流程(不需要做解密) |
| | | } |
| | | |
| | | //3. 解密 |
| | | String plainData = null; |
| | | if (isDataEncrypted) { |
| | | try { |
| | | plainData = AlipayEncrypt.decryptContent(content, encryptType, "VSpPcLQjLSoTz6Yd7KNoyQ==", charset); |
| | | } catch (AlipayApiException e) { |
| | | //解密异常, 记录日志 |
| | | e.getMessage(); |
| | | } |
| | | } else { |
| | | plainData = content; |
| | | } |
| | | |
| | | } |
| | | }else{ |
| | | WxMaJscode2SessionResult session = null; |
| | | String unionid; |
| | | String openid; |
| | | String sessionKey = null; |
| | | //获取session |
| | | session = wxMaService.getUserService().getSessionInfo(appMiniLoginDto.getCode()); |
| | | if (session != null && StringUtils.isNotBlank(session.getOpenid())) { |
| | | unionid = session.getUnionid(); |
| | | openid = session.getOpenid(); |
| | | sessionKey = session.getSessionKey(); |
| | | |
| | | |
| | | String responseAccessToken = getAccessTokenByWX(); |
| | | String responseAccessToken = null; |
| | | try { |
| | | responseAccessToken = getAccessTokenByWX(); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | |
| | | JSONObject jsonAccessToken = JSONObject.parseObject(responseAccessToken); |
| | | JSONObject jsonAccessToken = JSONObject.parseObject(responseAccessToken); |
| | | String accessToken = jsonAccessToken.getString("access_token"); |
| | | String errmsg = jsonAccessToken.getString("errmsg"); |
| | | Long expiresIn = jsonAccessToken.getLong("expires_in"); |
| | | if (StringUtils.isBlank(accessToken)) { |
| | | throw new ServiceException(errmsg); |
| | | } |
| | | String responseUserPhoneNumber = getMobileByWX(accessToken, appMiniLoginDto.getCode()); |
| | | JSONObject jsonUserPhoneNumber = JSONObject.parseObject(responseUserPhoneNumber); |
| | | String responseUserPhoneNumber = null; |
| | | try { |
| | | responseUserPhoneNumber = getMobileByWX(accessToken, appMiniLoginDto.getCode()); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | JSONObject jsonUserPhoneNumber = JSONObject.parseObject(responseUserPhoneNumber); |
| | | |
| | | |
| | | String phoneInfo = jsonUserPhoneNumber.getString("phone_info"); |
| | |
| | | R<SysUser> sysUserR = sysUserClient.queryUserByPhone(mobile); |
| | | SysUser data = sysUserR.getData(); |
| | | appMiniLoginVo.setSysUser(data); |
| | | |
| | | appMiniLoginVo.setMiniOpenid(openid); |
| | | appMiniLoginVo.setWxUnionid(unionid); |
| | | appMiniLoginVo.setPhone(mobile); |
| | | appMiniLoginVo.setSessionKey(sessionKey); |
| | | } |
| | | } |
| | | return appMiniLoginVo; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return null; |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | private AlipayUserInfoShareResponse getAliUserInfo (String accessToken) throws Exception { |
| | | |
| | | AlipayClient alipayClient = new DefaultAlipayClient(ALIPAY_BORDER_PROD,APP_ID_PROD, APP_PRIVATE_KEY, "json", "GBK", ALIPAY_PUBLIC_KEY, "RSA2"); |
| | | AlipayUserInfoShareRequest request = new AlipayUserInfoShareRequest(); |
| | | AlipayUserInfoShareResponse response = alipayClient.execute(request, accessToken); |
| | | if(response.isSuccess()){ |
| | | System.out.println("获取会员信息 - 调用成功"); |
| | | return response; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public PageDTO<MemberAuctionSalesroomVO> getMemberAuctionSalesroomList(MemberAuctionSalesroomDTO memberAuctionSalesroomDTO) { |