New file |
| | |
| | | package util; |
| | | |
| | | import com.obs.services.ObsClient; |
| | | import com.obs.services.model.ObjectMetadata; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.util.UUID; |
| | | |
| | | public class HuaWeiOBSUtil { |
| | | |
| | | //TODO 修改配置文件 |
| | | //OBS图片访问域名 |
| | | public static String endPoint = "obs.cn-southwest-2.myhuaweicloud.com"; |
| | | public static String accessKeyId = "IZB26ZHC7C5MWIOH1TGE"; |
| | | public static String accessKeySecret = "y5PXhFMDOHiPH0nnQMz4gkvA63oqKAC621zXzOPk"; |
| | | public static String bucketName = "mimishejiao"; |
| | | public static String oss_domain = "https://mimishejiao.obs.cn-southwest-2.myhuaweicloud.com/"; |
| | | |
| | | // 创建ObsClient实例 |
| | | public static ObsClient obsClient = new ObsClient(accessKeyId, accessKeySecret, endPoint); |
| | | |
| | | public static String obsUpload(MultipartFile file) |
| | | throws IOException { |
| | | //CommonsMultipartFile file = (CommonsMultipartFile)multipartFile; |
| | | String fileName = ""; |
| | | if (file != null && !"".equals(file.getOriginalFilename()) |
| | | && file.getOriginalFilename() != null) { |
| | | InputStream content = file.getInputStream();//获得指定文件的输入流 |
| | | ObjectMetadata meta = new ObjectMetadata();// 创建上传Object的Metadata |
| | | meta.setContentLength(file.getSize()); // 必须设置ContentLength |
| | | String originalFilename = file.getOriginalFilename(); |
| | | fileName = |
| | | UUID.randomUUID().toString().replaceAll("-", "") + originalFilename.subSequence( |
| | | originalFilename.lastIndexOf("."), originalFilename.length()); |
| | | obsClient.putObject(bucketName, fileName, content, meta);// 上传Object. |
| | | if (fileName != null && !"".equals(fileName)) { |
| | | System.out.println(fileName); |
| | | fileName = oss_domain + fileName; |
| | | } |
| | | } |
| | | return fileName; |
| | | } |
| | | |
| | | /** |
| | | * 删除某个Object |
| | | * |
| | | * @param bucketUrl |
| | | * @return |
| | | */ |
| | | public static boolean deleteObject(String bucketUrl) { |
| | | try { |
| | | bucketUrl = bucketUrl.replace(oss_domain, ""); |
| | | // 删除Object. |
| | | obsClient.deleteObject(bucketName, bucketUrl); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return false; |
| | | } finally { |
| | | // obsClient.shutdown(); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | // public static void createBucket(String bucketName) |
| | | // { |
| | | // //初始化 OSSClient |
| | | //// ossClient = new OssClient(endPoint, accessKeyId, accessKeySecret); |
| | | // |
| | | // // 新建一个Bucket |
| | | // Bucket bucket = ossClient.createBucket(bucketName); |
| | | // System.out.println(bucket.getName()); |
| | | // System.out.println(bucket.getCreationDate()); |
| | | // } |
| | | // |
| | | // public static void main(String[] args) { |
| | | // OssUploadUtil.createBucket("ssfdfsd"); |
| | | // } |
| | | } |
| | |
| | | salesroomGoods.setStatus(AuctionStartStatusEnum.ENDED); |
| | | iAuctionSalesroomGoodsService.updateById(salesroomGoods); |
| | | } |
| | | List<Long> list=new ArrayList<>(); |
| | | |
| | | |
| | | LambdaQueryWrapper<AuctionBidRecord> wrapper = Wrappers.lambdaQuery(); |
| | | wrapper.eq(AuctionBidRecord::getAuctionSalesroomId, SalesroomId); |
| | | wrapper.eq(AuctionBidRecord::getDelFlag, 0); |
| | | wrapper.eq(AuctionBidRecord::getStatus,0); |
| | | List<AuctionBidRecord>auctionBidRecordList = iAuctionBidRecordService.list(wrapper); |
| | | for (AuctionBidRecord auctionBidRecord:auctionBidRecordList){ |
| | | list.add(auctionBidRecord.getMemberId()); |
| | | } |
| | | if (list.size()>0){ |
| | | OrderAuctionBondDTO orderAuctionBondDTO=new OrderAuctionBondDTO(); |
| | | orderAuctionBondDTO.setAuctionSalesroomId(auctionSalesroom.getId()); |
| | | orderAuctionBondDTO.setUserList(list); |
| | | orderClient.getOrderAuctionBond(orderAuctionBondDTO); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | wrapper2.eq(AuctionSalesroomGoods::getDelFlag,0); |
| | | wrapper2.eq(AuctionSalesroomGoods::getGoodsSkuId,auctionSalesroomGoodsDTO.getGoodsSkuId()); |
| | | AuctionSalesroomGoods auctionSalesroomGood=iAuctionSalesroomGoodsService.getOne(wrapper2); |
| | | auctionSalesroomGood.setStatus(AuctionStartStatusEnum.ENDED); |
| | | iAuctionSalesroomGoodsService.updateById(auctionSalesroomGood); |
| | | |
| | | |
| | | AuctionSalesroom auctionSalesroom=iAuctionSalesroomService.getById(auctionSalesroomGood.getAuctionSalesroomId()); |
| | | |
| | | AuctionSalesroomGoods auctionSalesroomGoods=iAuctionSalesroomGoodsService.getById(auctionSalesroomGoodsDTO.getGoodsSkuId()); |
| | | List<AuctionBidRecord> auctionBidRecordList=new ArrayList<>(); |
| | | List<Long> list=new ArrayList<>(); |
| | | |
| | | if (auctionSalesroomGoods.getStatus().getCode()==1) { |
| | | LambdaQueryWrapper<AuctionBidRecord> wrapper = Wrappers.lambdaQuery(); |
| | | wrapper.eq(AuctionBidRecord::getGoodsSkuId, auctionSalesroomGoodsDTO.getGoodsSkuId()); |
| | |
| | | AuctionBidRecord auctionBidRecord = auctionBidRecordList.get(i); |
| | | auctionBidRecord.setStatus(BidStatusEnum.SUCCESSFUL); |
| | | AddOrder(auctionBidRecord.getGoodsSkuId(),auctionBidRecord.getMemberId(),auctionBidRecord.getLastBidAmount(),auctionSalesroom.getBound()); |
| | | |
| | | list.add(auctionBidRecord.getMemberId()); |
| | | } |
| | | } else { |
| | | for (int i = 0; i <= auctionBidRecordList.size(); i++) { |
| | | AuctionBidRecord auctionBidRecord = auctionBidRecordList.get(i); |
| | | auctionBidRecord.setStatus(BidStatusEnum.SUCCESSFUL); |
| | | AddOrder(auctionBidRecord.getGoodsSkuId(),auctionBidRecord.getMemberId(),auctionBidRecord.getLastBidAmount(),auctionSalesroom.getBound()); |
| | | list.add(auctionBidRecord.getMemberId()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | OrderAuctionBondDTO orderAuctionBondDTO=new OrderAuctionBondDTO(); |
| | | orderAuctionBondDTO.setAuctionSalesroomId(auctionSalesroom.getId()); |
| | | orderAuctionBondDTO.setUserList(list); |
| | | orderClient.getOrderAuctionBond(orderAuctionBondDTO); |
| | | auctionSalesroomGood.setStatus(AuctionStartStatusEnum.ENDED); |
| | | iAuctionSalesroomGoodsService.updateById(auctionSalesroomGood); |
| | | |
| | | } |
| | | |
| | |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>net.sf.json-lib</groupId> |
| | | <artifactId>json-lib</artifactId> |
| | | <version>2.4</version> |
| | | <classifier>jdk15</classifier> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>commons-httpclient</groupId> |
| | | <artifactId>commons-httpclient</artifactId> |
| | | <version>3.1</version> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>com.alipay.sdk</groupId> |
| | | <artifactId>alipay-sdk-java</artifactId> |
| | | <version>3.4.27.ALL</version> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>cn.afterturn</groupId> |
| | | <artifactId>easypoi-spring-boot-starter</artifactId> |
| | | <version>4.0.0</version> |
New file |
| | |
| | | package com.ruoyi.member.DTO; |
| | | |
| | | import com.ruoyi.common.core.enums.GenderEnum; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | |
| | | @Data |
| | | public class MemberDTO { |
| | | @ApiModelProperty(value = "会员id") |
| | | private Long memberid; |
| | | @ApiModelProperty(value = "1是支付寶,2是微信") |
| | | private Integer type; |
| | | @ApiModelProperty(value = "支付寶和微信唯一標識") |
| | | private String openid; |
| | | |
| | | @ApiModelProperty(value = "会员昵称") |
| | | private String nickname; |
| | | |
| | | @ApiModelProperty(value = "头像") |
| | | private String avatar; |
| | | |
| | | @ApiModelProperty(value = "会员姓名") |
| | | private String realName; |
| | | |
| | | @ApiModelProperty(value = "身份证号") |
| | | private String idNumber; |
| | | |
| | | @ApiModelProperty(value = "联系电话") |
| | | private String phone; |
| | | |
| | | @ApiModelProperty(value = "性别 0=女,1=男,2=未知") |
| | | private GenderEnum gender; |
| | | |
| | | } |
New file |
| | |
| | | package com.ruoyi.member.VO; |
| | | |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | |
| | | @Data |
| | | public class AlipayUser { |
| | | @ApiModelProperty("用戶ID") |
| | | private String userid; |
| | | private String Address; |
| | | private String CertNo; |
| | | private String City; |
| | | private String CollegeName; |
| | | private String Degree; |
| | | private String Mobile; |
| | | private String Phone; |
| | | private String Province; |
| | | private String UserName; |
| | | private String NickName; |
| | | } |
New file |
| | |
| | | package com.ruoyi.member.VO; |
| | | |
| | | import com.ruoyi.common.core.enums.GenderEnum; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | |
| | | @Data |
| | | public class MemberVO { |
| | | @ApiModelProperty(value = "1未认证,2已认证") |
| | | private Integer isAuthentication; |
| | | |
| | | @ApiModelProperty(value = "会员id") |
| | | private Long memberid; |
| | | |
| | | @ApiModelProperty(value = "会员昵称") |
| | | private String nickname; |
| | | |
| | | @ApiModelProperty(value = "头像") |
| | | private String avatar; |
| | | |
| | | @ApiModelProperty(value = "会员姓名") |
| | | private String realName; |
| | | |
| | | @ApiModelProperty(value = "身份证号") |
| | | private String idNumber; |
| | | |
| | | @ApiModelProperty(value = "联系电话") |
| | | private String phone; |
| | | |
| | | @ApiModelProperty(value = "性别 0=女,1=男,2=未知") |
| | | private GenderEnum gender; |
| | | |
| | | @ApiModelProperty(value = "等级") |
| | | private Integer level; |
| | | |
| | | @ApiModelProperty(value = "会员积分") |
| | | private Integer totalPoints; |
| | | |
| | | @ApiModelProperty(value = "已用积分") |
| | | private Integer usedPoints; |
| | | } |
New file |
| | |
| | | package com.ruoyi.member.controller; |
| | | |
| | | import com.alipay.api.AlipayApiException; |
| | | import com.alipay.api.AlipayClient; |
| | | import com.alipay.api.DefaultAlipayClient; |
| | | import com.alipay.api.request.AlipaySystemOauthTokenRequest; |
| | | import com.alipay.api.response.AlipaySystemOauthTokenResponse; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.member.VO.AlipayUser; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | |
| | | @Controller |
| | | @RequestMapping("/alipay") |
| | | public class AlipayAppController { |
| | | |
| | | /** |
| | | * Alipay客户端 |
| | | */ |
| | | private AlipayClient alipayClient; |
| | | |
| | | /**支付宝网关*/ |
| | | /** |
| | | * 沙箱的 |
| | | */ |
| | | private static final String ALIPAY_BORDER_DEV = "https://openapi-sandbox.dl.alipaydev.com/gateway.do"; |
| | | /** |
| | | * 个人用户的 |
| | | */ |
| | | private static final String ALIPAY_BORDER_PROD = "https://openapi.alipay.com/gateway.do"; |
| | | /** |
| | | * appID |
| | | **/ |
| | | private static final String APP_ID_PROD = "2021003196653501"; |
| | | /** |
| | | * 私钥 |
| | | */ |
| | | private static final String APP_PRIVATE_KEY = ""; |
| | | /** |
| | | * 支付宝公钥 |
| | | */ |
| | | private static final String ALIPAY_PUBLIC_KEY = ""; |
| | | |
| | | |
| | | @RequestMapping("/getalipayInfo") |
| | | @ApiOperation(value = "获取支付寶授权码") |
| | | public R<AlipayUser> getInfo(String auth_code) throws AlipayApiException { |
| | | //使用支付宝小程序的固定方法获取auth_code |
| | | if (auth_code == null || auth_code.length() == 0) { |
| | | return R.fail("请求参数auth_code不能为空"); |
| | | } else { |
| | | //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"); |
| | | AlipaySystemOauthTokenRequest request = new AlipaySystemOauthTokenRequest(); |
| | | // 值为authorization_code时,代表用code换取 |
| | | request.setGrantType("authorization_code"); |
| | | //授权码,用户对应用授权后得到的 |
| | | request.setCode(auth_code); |
| | | //这里使用execute方法 |
| | | AlipaySystemOauthTokenResponse response = alipayClient.execute(request); |
| | | //刷新令牌,上次换取访问令牌时得到。见出参的refresh_token字段 |
| | | request.setRefreshToken(response.getAccessToken()); |
| | | //返回成功时 就将唯一标识返回 |
| | | if (response.isSuccess()) { |
| | | System.out.println("调用成功"); |
| | | //我这里只返回了一个字段给前端用 |
| | | AlipayUser user=new AlipayUser(); |
| | | user.setUserid(response.getUserId()); |
| | | return R.ok(user); |
| | | } else { |
| | | return R.fail("调用失败"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | package com.ruoyi.member.controller; |
| | | |
| | | |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.member.DTO.MemberDTO; |
| | | import com.ruoyi.member.domain.pojo.Member; |
| | | import com.ruoyi.member.service.IMemberService; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.apache.poi.ss.formula.functions.T; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import org.springframework.web.multipart.MultipartHttpServletRequest; |
| | | import util.HuaWeiOBSUtil; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @RestController |
| | | @RequestMapping("/member") |
| | | public class MemberController { |
| | | @Resource |
| | | private IMemberService iMemberService; |
| | | @RequestMapping("/loginThird") |
| | | @ResponseBody |
| | | @ApiOperation(value = "第三方登陸和註冊") |
| | | public R<Member> loginThird(MemberDTO memberDTO) { |
| | | return R.ok(iMemberService.loginThird(memberDTO)); |
| | | } |
| | | |
| | | @RequestMapping("/getMembeid") |
| | | @ResponseBody |
| | | @ApiOperation(value = "获取用户信息") |
| | | public R<Member> getMembeid(MemberDTO memberDTO) { |
| | | return R.ok(iMemberService.getMembeid(memberDTO)); |
| | | } |
| | | |
| | | |
| | | @RequestMapping("/saveUserImg") |
| | | @ApiOperation(value = "修改头像") |
| | | public R<Member> saveNotice(HttpServletRequest request) { |
| | | try { |
| | | MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; |
| | | MultipartFile file = (MultipartFile) multipartRequest.getFile("images"); |
| | | String url=HuaWeiOBSUtil.obsUpload(file); |
| | | Member member=new Member(); |
| | | member.setAvatar(url); |
| | | return R.ok(member); |
| | | } catch (Exception e) { |
| | | return R.fail("保存图片失败"); |
| | | } |
| | | |
| | | } |
| | | |
| | | @RequestMapping("/updateMembeid") |
| | | @ResponseBody |
| | | @ApiOperation(value = "修改用户信息") |
| | | public R<T> updateMembeid(MemberDTO memberDTO) { |
| | | iMemberService.updateMembeid(memberDTO); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @RequestMapping("/authentificationMembe") |
| | | @ResponseBody |
| | | @ApiOperation(value = "用户认证") |
| | | public R<T> authentificationMembe(MemberDTO memberDTO) { |
| | | iMemberService.authentificationMembe(memberDTO); |
| | | return R.ok(); |
| | | } |
| | | } |
New file |
| | |
| | | package com.ruoyi.member.controller; |
| | | |
| | | import java.io.BufferedReader; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.InputStreamReader; |
| | | import java.net.MalformedURLException; |
| | | import java.net.URL; |
| | | import java.net.URLConnection; |
| | | import java.security.AlgorithmParameters; |
| | | import java.security.Security; |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | import javax.crypto.Cipher; |
| | | import javax.crypto.spec.IvParameterSpec; |
| | | import javax.crypto.spec.SecretKeySpec; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.utils.sign.Base64; |
| | | import com.ruoyi.member.util.*; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.stereotype.Controller; |
| | | 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"; |
| | | |
| | | @RequestMapping("/getAddress") |
| | | @ResponseBody |
| | | @ApiOperation(value = "获取微信的地址信息") |
| | | public R<Map<String, String>> getAddress(String url, HttpServletRequest request) { |
| | | Map<String,String> data=new HashMap<>(); |
| | | String jsapiTicket = JsapiTicketUtil.getJSApiTicket(); |
| | | Map<String, String> map = Sign.sign(jsapiTicket, url); |
| | | request.getSession().setAttribute("nonceStr", map.get("nonceStr")); |
| | | request.getSession().setAttribute("timestamp", map.get("timestamp")); |
| | | request.getSession().setAttribute("signature", map.get("signature")); |
| | | data.put("nonceStr", map.get("nonceStr")); |
| | | data.put("timestamp", map.get("timestamp")); |
| | | data.put("signature", map.get("signature")); |
| | | data.put("url",url); |
| | | data.put("jsapi_ticket", jsapiTicket); |
| | | return R.ok(map); |
| | | } |
| | | |
| | | @ResponseBody |
| | | @RequestMapping("/getOpenId") |
| | | @ApiOperation(value = "获取微信的OpenId") |
| | | public R<Map<String, String>> getOpenId(String code) { |
| | | try { |
| | | String openID = JsapiTicketUtil.getOpenId(code); |
| | | Map<String,String> data=new HashMap<>(); |
| | | data.put("openID",openID); |
| | | return R.ok(data); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return R.fail("获取异常"); |
| | | } |
| | | |
| | | @ResponseBody |
| | | @RequestMapping("getUserInfoAccessToken") |
| | | @ApiOperation(value = "获取微信的UserInfoAccessToken") |
| | | public R<String> getUserInfoAccessToken(String code) { |
| | | try { |
| | | //微信端登录code |
| | | String wxCode = code; |
| | | String requestUrl = "https://api.weixin.qq.com/sns/jscode2session"; |
| | | Map<String,String> requestUrlParam = new HashMap<String, String>( ); |
| | | requestUrlParam.put( "appid",appid);//小程序appId |
| | | requestUrlParam.put( "secret",appSecret ); |
| | | requestUrlParam.put( "js_code",wxCode );//小程序端返回的code |
| | | requestUrlParam.put( "grant_type","authorization_code" );//默认参数 |
| | | String jsonObject = HttpRequestUtil.getRequest(requestUrl,requestUrlParam ); |
| | | return R.ok(jsonObject); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return R.fail("获取异常"); |
| | | } |
| | | |
| | | @ResponseBody |
| | | @RequestMapping("/getRdSession") |
| | | @ApiOperation(value = "获取微信的Session") |
| | | public R<Map<String, String>> getRdSession(String code, String rdSession, HttpServletRequest request) { |
| | | try { |
| | | Map<String, String> map = new HashMap<>(); |
| | | if (SinataUtil.isNotEmpty(rdSession)) { |
| | | String str = (String) request.getSession().getAttribute(rdSession); |
| | | if (SinataUtil.isNotEmpty(str)) { |
| | | map = new HashMap<String, String>(); |
| | | map.put("rdSession", rdSession); |
| | | map.put("status", "1"); |
| | | map.put("appId", appid); |
| | | map.put("session_key", str); |
| | | } else { |
| | | map = new HashMap<String, String>(); |
| | | map.put("rdSession", rdSession); |
| | | map.put("status", "2");// 过期 |
| | | map.put("appId", appid); |
| | | map.put("session_key", str); |
| | | } |
| | | } |
| | | map = JsapiTicketUtil.getToken(code); |
| | | String openid = map.get("openid"); |
| | | String session_key = map.get("session_key"); |
| | | String rdSessions = new Date().getTime() + ""; |
| | | if (SinataUtil.isNotEmpty(openid)) { |
| | | request.getSession().setAttribute(rdSessions, session_key + openid); |
| | | map = new HashMap<String, String>(); |
| | | map.put("rdSession", rdSessions); |
| | | map.put("status", "1"); |
| | | map.put("appId", appid); |
| | | map.put("session_key", session_key); |
| | | } else { |
| | | map = new HashMap<String, String>(); |
| | | map.put("rdSession", rdSessions); |
| | | map.put("status", "3");// 获取失败 |
| | | map.put("appId", appid); |
| | | map.put("session_key", session_key); |
| | | } |
| | | |
| | | return R.ok(map); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return R.fail("获取异常"); |
| | | } |
| | | |
| | | /** |
| | | * 获取微信用户信息 |
| | | * |
| | | * @param token |
| | | * @param openid |
| | | * @return |
| | | */ |
| | | @ResponseBody |
| | | @RequestMapping("/getWXinfo") |
| | | @ApiOperation(value = "获取微信用户信息") |
| | | public R<Object> getWXinfo(String token, String openid) { |
| | | try { |
| | | String str = getJSApiTicket(token, openid); |
| | | return R.ok(str); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return R.fail("获取异常"); |
| | | } |
| | | |
| | | public static String getJSApiTicket(String token, String openid) { |
| | | // 获取token |
| | | // String acess_token= JsapiTicketUtil.getAccessToken(); |
| | | |
| | | String urlStr = "https://api.weixin.qq.com/sns/userinfo?access_token=" + token + "&openid=" + openid |
| | | + "&lang=zh_CN"; |
| | | String backData = sendGet(urlStr, "utf-8", 10000); |
| | | // String ticket = (String) |
| | | // JSONObject.fromObject(backData).get("ticket"); |
| | | return backData; |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 小程序使用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"; |
| | | String forObject = restTemplate.getForObject(url, String.class); |
| | | JSONObject jsonObject = JSON.parseObject(forObject); |
| | | int errcode = jsonObject.getIntValue("errcode"); |
| | | if(errcode == 0){//成功 |
| | | return forObject; |
| | | } |
| | | if(errcode == -1){//系统繁忙,此时请开发者稍候再试 |
| | | return jsonObject.getString("errmsg"); |
| | | } |
| | | if(errcode == 40029){//code 无效 |
| | | return jsonObject.getString("errmsg"); |
| | | } |
| | | if(errcode == 45011){//频率限制,每个用户每分钟100次 |
| | | 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 { |
| | | URL u = new URL(url); |
| | | try { |
| | | URLConnection conn = u.openConnection(); |
| | | conn.connect(); |
| | | conn.setConnectTimeout(timeout); |
| | | BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), charset)); |
| | | String line = ""; |
| | | while ((line = in.readLine()) != null) { |
| | | |
| | | result = result + line; |
| | | } |
| | | in.close(); |
| | | } catch (IOException e) { |
| | | return result; |
| | | } |
| | | } catch (MalformedURLException e) { |
| | | return result; |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | static void senMsg(String openId, String access_token, String namen, String OrderNum, String isstate) { |
| | | // 用户是否订阅该公众号标识 (0代表此用户没有关注该公众号 1表示关注了该公众号) |
| | | Integer state = WX_UserUtil.subscribeState(openId, access_token); |
| | | // 绑定了微信并且关注了服务号的用户 , 注册成功-推送注册短信 |
| | | if (state == 1) { |
| | | Map<String, TemplateData> param = new HashMap<>(); |
| | | param.put("first", new TemplateData(namen, "#696969")); |
| | | param.put("OrderSn", new TemplateData(OrderNum, "#696969")); |
| | | param.put("OrderStatus", new TemplateData(isstate, "#696969")); |
| | | // 调用发送微信消息给用户的接口 |
| | | WX_TemplateMsgUtil.sendWechatMsgToUser(openId, "RZfKB9pj1rIjrBIjFTiTss_NJzxGU11s0k6nf9fyi6w", "", "#000000", |
| | | WX_TemplateMsgUtil.packJsonmsg(param), access_token); |
| | | } |
| | | |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | Object phoneNumber = getPhoneNumber( |
| | | "vgq1QAPOVeBN3F4x5a/Gcq8SuCUiDb3S4g6AlMLnkueD3Gs0sVDygNd6JKSMgQjuYtEwFeFJH8jkR95pAUJIaedNiZSvwtwtuVBtgO0bs5n0aL3ALnTvyJ7j48x15mDi1tGQhSVamzi0qSf2lVCAsIvmoahraUdRts+HexODDr5YueIj9VELFLkyFP12ve2dO/vNwiUiNVnqwbGL4gq34Q==", |
| | | "0332NDK62xknkK0UAVL62oCvK622NDKr", "nB7w8ZM8obq3wY5OzMbDPg=="); |
| | | System.out.println(phoneNumber); |
| | | net.sf.json.JSONObject parse = net.sf.json.JSONObject.fromObject(phoneNumber); |
| | | System.out.println(parse.get("phoneNumber")); |
| | | } |
| | | |
| | | public static Object getPhoneNumber(String encryptedData, String code, String iv) { |
| | | Map<String, String> map = JsapiTicketUtil.getToken(code); |
| | | String session_key = ""; |
| | | if (map != null) { |
| | | // session_key = json.getString("session_key"); |
| | | session_key = map.get("session_key"); |
| | | // 被加密的数据 |
| | | byte[] dataByte = Base64.decode(encryptedData); |
| | | // 加密秘钥 |
| | | byte[] keyByte = Base64.decode(session_key); |
| | | // 偏移量 |
| | | byte[] ivByte = Base64.decode(iv); |
| | | try { |
| | | // 如果密钥不足16位,那么就补足. 这个if 中的内容很重要 |
| | | int base = 16; |
| | | if (keyByte.length % base != 0) { |
| | | int groups = keyByte.length / base + (keyByte.length % base != 0 ? 1 : 0); |
| | | byte[] temp = new byte[groups * base]; |
| | | Arrays.fill(temp, (byte) 0); |
| | | System.arraycopy(keyByte, 0, temp, 0, keyByte.length); |
| | | keyByte = temp; |
| | | } |
| | | // 初始化 |
| | | Security.addProvider(new BouncyCastleProvider()); |
| | | Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); |
| | | SecretKeySpec spec = new SecretKeySpec(keyByte, "AES"); |
| | | AlgorithmParameters parameters = AlgorithmParameters.getInstance("AES"); |
| | | parameters.init(new IvParameterSpec(ivByte)); |
| | | cipher.init(Cipher.DECRYPT_MODE, spec, parameters);// 初始化 |
| | | byte[] resultByte = cipher.doFinal(dataByte); |
| | | if (null != resultByte && resultByte.length > 0) { |
| | | String result = new String(resultByte, "UTF-8"); |
| | | return JSONObject.parseObject(result); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | } |
| | |
| | | @TableLogic |
| | | private Integer delFlag; |
| | | |
| | | @ApiModelProperty(value = "1未认证,2已认证") |
| | | private Integer isAuthentication; |
| | | |
| | | |
| | | |
| | | } |
| | |
| | | package com.ruoyi.member.service; |
| | | |
| | | import com.ruoyi.member.DTO.MemberDTO; |
| | | import com.ruoyi.member.domain.pojo.Member; |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | |
| | |
| | | */ |
| | | public interface IMemberService extends IService<Member> { |
| | | |
| | | Member loginThird(MemberDTO memberDTO); |
| | | |
| | | Member getMembeid(MemberDTO memberDTO); |
| | | |
| | | void updateMembeid(MemberDTO memberDTO); |
| | | |
| | | void authentificationMembe(MemberDTO memberDTO); |
| | | |
| | | } |
| | |
| | | package com.ruoyi.member.service.impl; |
| | | |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.ruoyi.common.core.enums.GenderEnum; |
| | | import com.ruoyi.common.core.exception.ServiceException; |
| | | import org.apache.commons.io.IOUtils; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.member.DTO.MemberDTO; |
| | | import com.ruoyi.member.domain.pojo.Member; |
| | | import com.ruoyi.member.mapper.MemberMapper; |
| | | import com.ruoyi.member.service.IMemberService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.apache.http.HttpEntity; |
| | | import org.apache.http.client.config.RequestConfig; |
| | | import org.apache.http.client.methods.CloseableHttpResponse; |
| | | import org.apache.http.client.methods.HttpGet; |
| | | import org.apache.http.impl.client.CloseableHttpClient; |
| | | import org.apache.http.impl.client.HttpClients; |
| | | import org.apache.http.util.EntityUtils; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.IOException; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.net.URLEncoder; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Service |
| | | public class MemberServiceImpl extends ServiceImpl<MemberMapper, Member> implements IMemberService { |
| | | |
| | | |
| | | public static RequestConfig config = RequestConfig.custom().setConnectTimeout(5000).setSocketTimeout(5000).build(); |
| | | // 配置您申请的KEY,在个人中心->我的数据,接口名称上方查看 |
| | | public static final String APPKEY = ""; |
| | | //明文查询地址 |
| | | public static String query_url = "http://op.juhe.cn/idcard/query?key=" + APPKEY; |
| | | |
| | | |
| | | @Resource |
| | | private IMemberService iMemberService; |
| | | @Override |
| | | public Member loginThird(MemberDTO memberDTO) { |
| | | try { |
| | | if (memberDTO.getType() == 1) { |
| | | LambdaQueryWrapper<Member> wrapper= Wrappers.lambdaQuery(); |
| | | wrapper.eq(Member::getZfbOpenid,memberDTO.getOpenid()); |
| | | Member member=iMemberService.getOne(wrapper); |
| | | if (member==null){ |
| | | Member m=new Member(); |
| | | m.setZfbOpenid(memberDTO.getOpenid()); |
| | | m.setNickname("未知"); |
| | | m.setLevel(0); |
| | | m.setAvatar(""); |
| | | iMemberService.save(m); |
| | | return m; |
| | | }else { |
| | | |
| | | return member; |
| | | } |
| | | |
| | | } |
| | | if (memberDTO.getType() == 2) { |
| | | LambdaQueryWrapper<Member> wrapper= Wrappers.lambdaQuery(); |
| | | wrapper.eq(Member::getWxOpenid,memberDTO.getOpenid()); |
| | | Member member=iMemberService.getOne(wrapper); |
| | | if (member==null){ |
| | | Member m=new Member(); |
| | | m.setZfbOpenid(memberDTO.getOpenid()); |
| | | m.setNickname("未知"); |
| | | m.setLevel(0); |
| | | m.setAvatar(""); |
| | | iMemberService.save(m); |
| | | return m; |
| | | }else { |
| | | |
| | | return member; |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public Member getMembeid(MemberDTO memberDTO) { |
| | | return iMemberService.getById(memberDTO.getMemberid()); |
| | | } |
| | | |
| | | @Override |
| | | public void updateMembeid(MemberDTO memberDTO) { |
| | | Member member= iMemberService.getById(memberDTO.getMemberid()); |
| | | if (memberDTO.getAvatar()!=null){ |
| | | member.setAvatar(memberDTO.getAvatar()); |
| | | } |
| | | if (memberDTO.getNickname()!=null){ |
| | | member.setNickname(memberDTO.getNickname()); |
| | | } |
| | | iMemberService.updateById(member); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void authentificationMembe(MemberDTO memberDTO) { |
| | | Member member= iMemberService.getById(memberDTO.getMemberid()); |
| | | member.setPhone(memberDTO.getPhone()); |
| | | member.setIdNumber(memberDTO.getIdNumber()); |
| | | member.setRealName(memberDTO.getRealName()); |
| | | |
| | | String realname = "";// 姓名 |
| | | String idcard = "";// 身份证 |
| | | int type = 1;// 普通版,不需要加密 |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("realname", realname); |
| | | params.put("idcard", idcard); |
| | | |
| | | CloseableHttpClient httpClient = HttpClients.createDefault(); |
| | | CloseableHttpResponse response = null; |
| | | String result = null; |
| | | String url = query_url; |
| | | try { |
| | | url = new StringBuffer(url).append("&").append(urlencode(params)).toString(); |
| | | HttpGet httpget = new HttpGet(url); |
| | | httpget.setConfig(config); |
| | | response = httpClient.execute(httpget); |
| | | HttpEntity resEntity = response.getEntity(); |
| | | if (resEntity != null) { |
| | | result = IOUtils.toString(resEntity.getContent(), "UTF-8"); |
| | | } |
| | | EntityUtils.consume(resEntity); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | try { |
| | | response.close(); |
| | | httpClient.close(); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | JSONObject jsonObject= JSON.parseObject(result); |
| | | String object= jsonObject.get("result").toString(); |
| | | JSONObject jsonObject1= JSON.parseObject(object); |
| | | if (Integer.valueOf(jsonObject1.get("res").toString())==2){ |
| | | throw new ServiceException("实名认证失败"); |
| | | } |
| | | |
| | | String sex=getGender(idcard); |
| | | if (sex.equals("女")){ |
| | | member.setGender(GenderEnum.FEMALE); |
| | | } |
| | | if (sex.equals("男")){ |
| | | member.setGender(GenderEnum.MALE); |
| | | } |
| | | |
| | | iMemberService.updateById(member); |
| | | } |
| | | |
| | | public static String getGender(String idNumber) { |
| | | int genderNum = Integer.parseInt(idNumber.substring(16, 17)); |
| | | return genderNum % 2 == 0 ? "女" : "男"; |
| | | } |
| | | |
| | | |
| | | public static String urlencode(Map<String, ?> data) { |
| | | StringBuilder sb = new StringBuilder(); |
| | | for (Map.Entry<String, ?> i : data.entrySet()) { |
| | | try { |
| | | sb.append(i.getKey()).append("=").append(URLEncoder.encode(i.getValue() + "", "UTF-8")).append("&"); |
| | | } catch (UnsupportedEncodingException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | String result = sb.toString(); |
| | | result = result.substring(0, result.lastIndexOf("&")); |
| | | return result; |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | |
New file |
| | |
| | | package com.ruoyi.member.util; |
| | | |
| | | import java.io.IOException; |
| | | |
| | | import java.io.PrintWriter; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import net.sf.json.JSONArray; |
| | | import net.sf.json.JSONObject; |
| | | import org.apache.commons.httpclient.HttpClient; |
| | | import org.apache.commons.httpclient.HttpException; |
| | | import org.apache.commons.httpclient.SimpleHttpConnectionManager; |
| | | import org.apache.commons.httpclient.methods.GetMethod; |
| | | import org.apache.commons.httpclient.methods.PostMethod; |
| | | |
| | | public class HttpRequestUtil { |
| | | |
| | | public static String postRequest(String url, Map<String, String> params) { |
| | | // 构造HttpClient的实例 |
| | | HttpClient httpClient = new HttpClient(); |
| | | // 创建POST方法的实例 |
| | | PostMethod postMethod = new PostMethod(url); |
| | | // 设置请求头信息 |
| | | postMethod.setRequestHeader("Connection", "close"); |
| | | postMethod.addRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8"); |
| | | // 添加参数 |
| | | for (Map.Entry<String, String> entry : params.entrySet()) { |
| | | postMethod.addParameter(entry.getKey(), entry.getValue()); |
| | | } |
| | | // 使用系统提供的默认的恢复策略,设置请求重试处理,用的是默认的重试处理:请求三次 |
| | | httpClient.getParams().setBooleanParameter("http.protocol.expect-continue", false); |
| | | // 接收处理结果 |
| | | String result = null; |
| | | try { |
| | | // 执行Http Post请求 |
| | | httpClient.executeMethod(postMethod); |
| | | // 返回处理结果 |
| | | result = postMethod.getResponseBodyAsString(); |
| | | } catch (HttpException e) { |
| | | // 发生致命的异常,可能是协议不对或者返回的内容有问题 |
| | | System.out.println("请检查输入的URL!"); |
| | | e.printStackTrace(); |
| | | } catch (IOException e) { |
| | | // 发生网络异常 |
| | | System.out.println("发生网络异常!"); |
| | | e.printStackTrace(); |
| | | } finally { |
| | | // 释放链接 |
| | | postMethod.releaseConnection(); |
| | | // 关闭HttpClient实例 |
| | | if (httpClient != null) { |
| | | ((SimpleHttpConnectionManager) httpClient.getHttpConnectionManager()).shutdown(); |
| | | httpClient = null; |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** post请求带header信息 **/ |
| | | public static String postRequest(String url, Map<String, String> headers, Map<String, String> params) { |
| | | // 构造HttpClient的实例 |
| | | HttpClient httpClient = new HttpClient(); |
| | | // 创建POST方法的实例 |
| | | PostMethod postMethod = new PostMethod(url); |
| | | // 设置请求头信息 |
| | | for (Map.Entry<String, String> entry : headers.entrySet()) { |
| | | postMethod.setRequestHeader(entry.getKey(), entry.getValue()); |
| | | } |
| | | // 添加参数 |
| | | for (Map.Entry<String, String> entry : params.entrySet()) { |
| | | postMethod.addParameter(entry.getKey(), entry.getValue()); |
| | | } |
| | | // 使用系统提供的默认的恢复策略,设置请求重试处理,用的是默认的重试处理:请求三次 |
| | | httpClient.getParams().setBooleanParameter("http.protocol.expect-continue", false); |
| | | // 接收处理结果 |
| | | String result = null; |
| | | try { |
| | | // 执行Http Post请求 |
| | | httpClient.executeMethod(postMethod); |
| | | // 返回处理结果 |
| | | result = postMethod.getResponseBodyAsString(); |
| | | } catch (HttpException e) { |
| | | // 发生致命的异常,可能是协议不对或者返回的内容有问题 |
| | | System.out.println("请检查输入的URL!"); |
| | | e.printStackTrace(); |
| | | } catch (IOException e) { |
| | | // 发生网络异常 |
| | | System.out.println("发生网络异常!"); |
| | | e.printStackTrace(); |
| | | } finally { |
| | | // 释放链接 |
| | | postMethod.releaseConnection(); |
| | | // 关闭HttpClient实例 |
| | | if (httpClient != null) { |
| | | ((SimpleHttpConnectionManager) httpClient.getHttpConnectionManager()).shutdown(); |
| | | httpClient = null; |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** post请求带header信息 **/ |
| | | public static String postRequest2(String url, Map<String, String> headers, Map<String, Object> params) { |
| | | // 构造HttpClient的实例 |
| | | HttpClient httpClient = new HttpClient(); |
| | | // 创建POST方法的实例 |
| | | PostMethod postMethod = new PostMethod(url); |
| | | // 设置请求头信息 |
| | | for (Map.Entry<String, String> entry : headers.entrySet()) { |
| | | postMethod.setRequestHeader(entry.getKey(), entry.getValue()); |
| | | } |
| | | // 添加参数 |
| | | for (Map.Entry<String, Object> entry : params.entrySet()) { |
| | | if (entry.getValue() instanceof List) { |
| | | postMethod.addParameter(entry.getKey(), JSONArray.fromObject(entry.getValue()).toString()); |
| | | } else { |
| | | postMethod.addParameter(entry.getKey(), JSONObject.fromObject(entry.getValue()).toString()); |
| | | } |
| | | } |
| | | // 使用系统提供的默认的恢复策略,设置请求重试处理,用的是默认的重试处理:请求三次 |
| | | httpClient.getParams().setBooleanParameter("http.protocol.expect-continue", false); |
| | | // 接收处理结果 |
| | | String result = null; |
| | | try { |
| | | // 执行Http Post请求 |
| | | httpClient.executeMethod(postMethod); |
| | | // 返回处理结果 |
| | | result = postMethod.getResponseBodyAsString(); |
| | | } catch (HttpException e) { |
| | | // 发生致命的异常,可能是协议不对或者返回的内容有问题 |
| | | System.out.println("请检查输入的URL!"); |
| | | e.printStackTrace(); |
| | | } catch (IOException e) { |
| | | // 发生网络异常 |
| | | System.out.println("发生网络异常!"); |
| | | e.printStackTrace(); |
| | | } finally { |
| | | // 释放链接 |
| | | postMethod.releaseConnection(); |
| | | // 关闭HttpClient实例 |
| | | if (httpClient != null) { |
| | | ((SimpleHttpConnectionManager) httpClient.getHttpConnectionManager()).shutdown(); |
| | | httpClient = null; |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | public static String getRequest(String url, Map<String, String> params) { |
| | | // 构造HttpClient实例 |
| | | HttpClient client = new HttpClient(); |
| | | // 拼接参数 |
| | | String paramStr = ""; |
| | | for (String key : params.keySet()) { |
| | | paramStr = paramStr + "&" + key + "=" + params.get(key); |
| | | } |
| | | paramStr = paramStr.substring(1); |
| | | // 创建GET方法的实例 |
| | | GetMethod method = new GetMethod(url + "?" + paramStr); |
| | | // 接收返回结果 |
| | | String result = null; |
| | | try { |
| | | // 执行HTTP GET方法请求 |
| | | client.executeMethod(method); |
| | | // 返回处理结果 |
| | | result = method.getResponseBodyAsString(); |
| | | } catch (HttpException e) { |
| | | // 发生致命的异常,可能是协议不对或者返回的内容有问题 |
| | | System.out.println("请检查输入的URL!"); |
| | | e.printStackTrace(); |
| | | } catch (IOException e) { |
| | | // 发生网络异常 |
| | | System.out.println("发生网络异常!"); |
| | | e.printStackTrace(); |
| | | } finally { |
| | | // 释放链接 |
| | | method.releaseConnection(); |
| | | // 关闭HttpClient实例 |
| | | if (client != null) { |
| | | ((SimpleHttpConnectionManager) client.getHttpConnectionManager()).shutdown(); |
| | | client = null; |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 发送网络请求 |
| | | * |
| | | * @param url |
| | | * @return |
| | | */ |
| | | public static String sendNetRequest(String url, Map<String, String> params) { |
| | | // 构造HttpClient实例 |
| | | HttpClient client = new HttpClient(); |
| | | String paramStr = ""; |
| | | for (String key : params.keySet()) { |
| | | paramStr = paramStr + "&" + key + "=" + params.get(key); |
| | | } |
| | | paramStr = paramStr.substring(1); |
| | | System.err.println(url + "?" + paramStr); |
| | | // 创建GET方法的实例 |
| | | GetMethod method = new GetMethod(url + "?" + paramStr); |
| | | // 接收返回结果 |
| | | String result = null; |
| | | try { |
| | | // 执行HTTP GET方法请求 |
| | | client.executeMethod(method); |
| | | // 返回处理结果 |
| | | result = method.getResponseBodyAsString(); |
| | | } catch (HttpException e) { |
| | | // 发生致命的异常,可能是协议不对或者返回的内容有问题 |
| | | System.out.println("请检查输入的URL!"); |
| | | e.printStackTrace(); |
| | | } catch (IOException e) { |
| | | // 发生网络异常 |
| | | System.out.println("发生网络异常!"); |
| | | e.printStackTrace(); |
| | | } finally { |
| | | // 释放链接 |
| | | method.releaseConnection(); |
| | | // 关闭HttpClient实例 |
| | | if (client != null) { |
| | | ((SimpleHttpConnectionManager) client.getHttpConnectionManager()).shutdown(); |
| | | client = null; |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * jsonp跨域请求数据响应<br/> |
| | | * 方法名:responsejsonpData<br/> |
| | | * @author:Mryang<br/> |
| | | * |
| | | * @createTime:2016年7月31日-下午11:17:31 <br/> |
| | | * @tel: 15198268054<br/> |
| | | * @param request |
| | | * @param response |
| | | * @param map |
| | | * void<br/> |
| | | * @exception <br/> |
| | | * @since 1.0.0 |
| | | */ |
| | | public void responsejsonpData(HttpServletRequest request, HttpServletResponse response, Map<String, Object> map) { |
| | | response.setCharacterEncoding("UTF-8"); |
| | | response.setHeader("Content-Type", "text/html;Charset=utf-8"); |
| | | try { |
| | | PrintWriter writer = response.getWriter(); |
| | | String params = request.getParameter("callback"); |
| | | String json = JSONObject.fromObject(map).toString(); |
| | | writer.print(params + "(" + json + ")"); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.ruoyi.member.util; |
| | | |
| | | |
| | | import java.io.BufferedReader; |
| | | import java.io.IOException; |
| | | import java.io.InputStreamReader; |
| | | import java.net.MalformedURLException; |
| | | import java.net.URL; |
| | | import java.net.URLConnection; |
| | | import java.net.URLEncoder; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | |
| | | import com.alibaba.nacos.shaded.com.google.gson.Gson; |
| | | import com.alibaba.nacos.shaded.com.google.gson.JsonObject; |
| | | import net.sf.json.JSONObject; |
| | | import org.apache.http.HttpEntity; |
| | | import org.apache.http.HttpResponse; |
| | | import org.apache.http.client.methods.HttpGet; |
| | | import org.apache.http.impl.client.DefaultHttpClient; |
| | | import org.apache.http.util.EntityUtils; |
| | | |
| | | |
| | | /*** |
| | | * @author V型知识库 www.vxzsk.com |
| | | * |
| | | */ |
| | | public class JsapiTicketUtil { |
| | | |
| | | private static String appid = "wx0e4769839d84fde0"; |
| | | private static String appSecret = "ede69db0303ddde49b5db95f186918ec"; |
| | | |
| | | |
| | | /*** |
| | | * 模拟get请求 |
| | | * @param url |
| | | * @param charset |
| | | * @param timeout |
| | | * @return |
| | | */ |
| | | public static String sendGet(String url, String charset, int timeout) |
| | | { |
| | | String result = ""; |
| | | try |
| | | { |
| | | URL u = new URL(url); |
| | | try |
| | | { |
| | | URLConnection conn = u.openConnection(); |
| | | conn.connect(); |
| | | conn.setConnectTimeout(timeout); |
| | | BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), charset)); |
| | | String line=""; |
| | | while ((line = in.readLine()) != null) |
| | | { |
| | | |
| | | result = result + line; |
| | | } |
| | | in.close(); |
| | | } catch (IOException e) { |
| | | return result; |
| | | } |
| | | } |
| | | catch (MalformedURLException e) |
| | | { |
| | | return result; |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | /*** |
| | | * 获取acess_token |
| | | * 来源www.vxzsk.com |
| | | * @return |
| | | */ |
| | | public static String getAccessToken(){ |
| | | String url ="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+appid+"&secret="+appSecret+""; |
| | | String backData=sendGet(url, "utf-8", 10000); |
| | | String accessToken = (String) JSONObject.fromObject(backData).get("access_token"); |
| | | return accessToken; |
| | | } |
| | | /*** |
| | | * 获取jsapiTicket |
| | | * 来源 www.vxzsk.com |
| | | * @return |
| | | */ |
| | | public static String getJSApiTicket(){ |
| | | //获取token |
| | | String acess_token= JsapiTicketUtil.getAccessToken(); |
| | | |
| | | String urlStr = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token="+acess_token+"&type=jsapi"; |
| | | String backData=sendGet(urlStr, "utf-8", 10000); |
| | | String ticket = (String) JSONObject.fromObject(backData).get("ticket"); |
| | | return ticket; |
| | | |
| | | } |
| | | /** |
| | | * 获取用户openid |
| | | * @return |
| | | */ |
| | | public static String getOpenId(String code){ |
| | | |
| | | String urlStr = "https://api.weixin.qq.com/sns/oauth2/access_token?appid="+appid+"&secret="+appSecret+"&code="+code+"&grant_type=authorization_code"; |
| | | String backData=sendGet(urlStr, "utf-8", 10000); |
| | | System.out.println(backData); |
| | | String ticket = (String) JSONObject.fromObject(backData).get("openid"); |
| | | return ticket; |
| | | |
| | | } |
| | | /** |
| | | * 获取请求用户信息的access_token |
| | | * |
| | | * @param code |
| | | * @return |
| | | */ |
| | | public static Map<String, String> getUserInfoAccessToken(String code) { |
| | | JsonObject object = null; |
| | | Map<String, String> data = new HashMap(); |
| | | try { |
| | | String url = String.format("https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code", |
| | | appid,appSecret, code); |
| | | DefaultHttpClient httpClient = new DefaultHttpClient(); |
| | | HttpGet httpGet = new HttpGet(url); |
| | | HttpResponse httpResponse = httpClient.execute(httpGet); |
| | | HttpEntity httpEntity = httpResponse.getEntity(); |
| | | String tokens = EntityUtils.toString(httpEntity, "utf-8"); |
| | | System.out.println(tokens); |
| | | Gson token_gson = new Gson(); |
| | | object = token_gson.fromJson(tokens, JsonObject.class); |
| | | data.put("openid", object.get("openid").toString().replaceAll("\"", "")); |
| | | data.put("access_token", object.get("access_token").toString().replaceAll("\"", "")); |
| | | } catch (Exception ex) { |
| | | } |
| | | return data; |
| | | } |
| | | public static String getCode(){ |
| | | JsonObject object = null; |
| | | Map<String, String> data = new HashMap(); |
| | | try { |
| | | String codes = String.format("https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=%s&state=%s#wechat_redirect", |
| | | appid, "http://www.txciot.com/resources/html/first.html", "snsapi_base", "xxxx_state"); |
| | | DefaultHttpClient httpClient = new DefaultHttpClient(); |
| | | return sendGet(codes, "utf-8", 10000); |
| | | } catch (Exception ex) { |
| | | return ""; |
| | | } |
| | | } |
| | | public static void main(String[] args) { |
| | | System.out.println(URLEncoder.encode("http://www.txciot.com/resources/html/first.html")); |
| | | System.out.println(getUserInfoAccessToken(getCode())); |
| | | } |
| | | |
| | | public static Map<String, String> getToken(String code) { |
| | | JsonObject object = null; |
| | | Map<String, String> data = new HashMap(); |
| | | try { |
| | | String url = String.format("https://api.weixin.qq.com/sns/jscode2session?appid=%s&secret=%s&js_code=%s&grant_type=authorization_code", |
| | | appid,appSecret, code); |
| | | DefaultHttpClient httpClient = new DefaultHttpClient(); |
| | | HttpGet httpGet = new HttpGet(url); |
| | | HttpResponse httpResponse = httpClient.execute(httpGet); |
| | | HttpEntity httpEntity = httpResponse.getEntity(); |
| | | String tokens = EntityUtils.toString(httpEntity, "utf-8"); |
| | | Gson token_gson = new Gson(); |
| | | object = token_gson.fromJson(tokens, JsonObject.class); |
| | | data.put("openid", object.get("openid").toString().replaceAll("\"", "")); |
| | | data.put("session_key", object.get("session_key").toString().replaceAll("\"", "")); |
| | | } catch (Exception ex) { |
| | | } |
| | | return data; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.ruoyi.member.util; |
| | | |
| | | import java.security.cert.CertificateException; |
| | | import java.security.cert.X509Certificate; |
| | | |
| | | import javax.net.ssl.X509TrustManager; |
| | | |
| | | public class MyX509TrustManager implements X509TrustManager { |
| | | @Override |
| | | public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { |
| | | } |
| | | @Override public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { } |
| | | @Override public X509Certificate[] getAcceptedIssuers() { |
| | | // return new X509Certificate[0]; |
| | | return null; |
| | | } |
| | | } |
New file |
| | |
| | | package com.ruoyi.member.util; |
| | | |
| | | |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.security.MessageDigest; |
| | | import java.security.NoSuchAlgorithmException; |
| | | import java.util.Formatter; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.UUID; |
| | | |
| | | public class Sign { |
| | | public static void main(String[] args) { |
| | | String jsapi_ticket = JsapiTicketUtil.getJSApiTicket(); |
| | | |
| | | // 注意 URL 一定要动态获取,不能 hardcode |
| | | //jsapi_ticket=HoagFKDcsGMVCIY2vOjf9mBNDeeIwVFa87uu4eC580T8dD8QHL3b2UPfwlJICyKEblD53boLr2El0_ehC3eA1Q |
| | | //&noncestr=360580f1-d5f1-40ae-8f9d-164a48cce732×tamp=1490077002&url=http://www.txciot.com/resources/html/test.html |
| | | |
| | | String url = "http://m.sinata.cn/test.html"; |
| | | Map<String, String> ret = sign("HoagFKDcsGMVCIY2vOjf9mBNDeeIwVFa87uu4eC580T8dD8QHL3b2UPfwlJICyKEblD53boLr2El0_ehC3eA1Q", "http://www.txciot.com/resources/html/test.html"); |
| | | for (Map.Entry entry : ret.entrySet()) { |
| | | System.out.println(entry.getKey() + ", " + entry.getValue()); |
| | | } |
| | | }; |
| | | |
| | | public static Map<String, String> sign(String jsapi_ticket, String url) { |
| | | Map<String, String> ret = new HashMap<String, String>(); |
| | | String nonce_str = create_nonce_str(); |
| | | String timestamp = create_timestamp(); |
| | | String string1; |
| | | String signature = ""; |
| | | |
| | | //注意这里参数名必须全部小写,且必须有序 |
| | | string1 = "jsapi_ticket=" + jsapi_ticket + |
| | | "&noncestr=" + nonce_str + |
| | | "×tamp=" + timestamp + |
| | | "&url=" + url; |
| | | System.out.println(string1); |
| | | |
| | | try |
| | | { |
| | | MessageDigest crypt = MessageDigest.getInstance("SHA-1"); |
| | | crypt.reset(); |
| | | crypt.update(string1.getBytes("UTF-8")); |
| | | signature = byteToHex(crypt.digest()); |
| | | } |
| | | catch (NoSuchAlgorithmException e) |
| | | { |
| | | e.printStackTrace(); |
| | | } |
| | | catch (UnsupportedEncodingException e) |
| | | { |
| | | e.printStackTrace(); |
| | | } |
| | | //ba32b6db5c20fe62b9261d3cce03fcc6950a53ed |
| | | //ba32b6db5c20fe62b9261d3cce03fcc6950a53ed |
| | | ret.put("url", url); |
| | | ret.put("jsapi_ticket", jsapi_ticket); |
| | | ret.put("nonceStr", nonce_str); |
| | | ret.put("timestamp", timestamp); |
| | | ret.put("signature", signature); |
| | | |
| | | return ret; |
| | | } |
| | | |
| | | private static String byteToHex(final byte[] hash) { |
| | | Formatter formatter = new Formatter(); |
| | | for (byte b : hash) |
| | | { |
| | | formatter.format("%02x", b); |
| | | } |
| | | String result = formatter.toString(); |
| | | formatter.close(); |
| | | return result; |
| | | } |
| | | |
| | | private static String create_nonce_str() { |
| | | return UUID.randomUUID().toString(); |
| | | } |
| | | |
| | | private static String create_timestamp() { |
| | | return Long.toString(System.currentTimeMillis() / 1000); |
| | | } |
| | | } |
New file |
| | |
| | | package com.ruoyi.member.util; |
| | | |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.text.DecimalFormat; |
| | | import java.text.NumberFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.UUID; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | |
| | | /** |
| | | * 基本数据处理工具类 |
| | | */ |
| | | public class SinataUtil { |
| | | |
| | | |
| | | /** |
| | | * List集合分页<br/> |
| | | * 创建人:Mryang<br/> |
| | | * 时间:2016年7月28日-下午2:58:14 <br/> |
| | | * @param <T> |
| | | * @param pageNo |
| | | * @param pageSize |
| | | * @param list |
| | | * @throws Exception List<UserOrderList> <br/> |
| | | */ |
| | | public static <T> List<T> listpage(int pageNo, int pageSize, List<T> list) throws Exception { |
| | | List<T> result = new ArrayList<T>(); |
| | | if (list != null && list.size() > 0) { |
| | | int allCount = list.size(); |
| | | if(pageNo > 1 && allCount < pageSize) { |
| | | return new ArrayList<>(); |
| | | } |
| | | int pageCount = (allCount + pageSize - 1) / pageSize; |
| | | if (pageNo >= pageCount) { |
| | | pageNo = pageCount; |
| | | } |
| | | int start = (pageNo - 1) * pageSize; |
| | | int end = pageNo * pageSize; |
| | | if (end >= allCount) { |
| | | end = allCount; |
| | | } |
| | | for (int i = start; i < end; i++) { |
| | | result.add(list.get(i)); |
| | | } |
| | | } |
| | | return (result != null && result.size() > 0) ? result : new ArrayList<T>(); |
| | | } |
| | | |
| | | /** |
| | | * Double类型取整 |
| | | * @param num |
| | | * @return |
| | | */ |
| | | public static String doubleTrans(double num) { |
| | | return String.valueOf((long) num); |
| | | } |
| | | |
| | | /** |
| | | * Double类型保留1位小数 |
| | | * |
| | | * @param num |
| | | * @return |
| | | */ |
| | | public static String doubleRetainOne(double num) { |
| | | DecimalFormat dfs = new DecimalFormat("0.0"); |
| | | return dfs.format(num); |
| | | } |
| | | |
| | | /** |
| | | * Double类型保留2位小数 |
| | | * |
| | | * @param num |
| | | * @return |
| | | */ |
| | | public static String doubleRetainTwo(double num) { |
| | | DecimalFormat dfs = new DecimalFormat("0.00"); |
| | | String.format("%.2f", num); |
| | | return dfs.format(num); |
| | | } |
| | | |
| | | /** |
| | | * Double类型保留1位小数(四舍五入) |
| | | * |
| | | * @param num |
| | | * @return |
| | | */ |
| | | public static String doubleForwardOne(double num) { |
| | | return String.format("%.1f", num); |
| | | } |
| | | |
| | | /** |
| | | * Double类型保留2位小数(四舍五入) |
| | | * |
| | | * @param num |
| | | * @return |
| | | */ |
| | | public static String doubleForwardTwo(double num) { |
| | | return String.format("%.2f", num); |
| | | } |
| | | |
| | | /** |
| | | * 字符串转换成Ascii |
| | | * |
| | | * @param value |
| | | * @return |
| | | */ |
| | | public static String stringToAscii(String value) { |
| | | StringBuffer sbu = new StringBuffer(); |
| | | char[] chars = value.toCharArray(); |
| | | for (int i = 0; i < chars.length; i++) { |
| | | if (i != chars.length - 1) { |
| | | sbu.append((int) chars[i]); |
| | | } else { |
| | | sbu.append((int) chars[i]); |
| | | } |
| | | } |
| | | return sbu.toString(); |
| | | } |
| | | |
| | | /** |
| | | * 小数转换为百分比 |
| | | * |
| | | * @param decimal |
| | | * @return |
| | | * @author TaoNingBo |
| | | */ |
| | | public static String decTurnPercent(double decimal) { |
| | | NumberFormat num = NumberFormat.getPercentInstance(); |
| | | num.setMaximumIntegerDigits(3); |
| | | num.setMaximumFractionDigits(2); |
| | | return num.format(decimal); |
| | | } |
| | | |
| | | /** |
| | | * Ascii转换成字符串 |
| | | * |
| | | * @param value |
| | | * @return |
| | | */ |
| | | public static String asciiToString(String value) { |
| | | String[] chars = value.split(","); |
| | | StringBuffer sbu = new StringBuffer(); |
| | | for (int i = 0; i < chars.length; i++) { |
| | | sbu.append((char) Integer.parseInt(chars[i])); |
| | | } |
| | | return sbu.toString(); |
| | | } |
| | | |
| | | /** |
| | | * 字符串转换unicode |
| | | * |
| | | * @param string |
| | | * @return |
| | | * @author TaoNingBo |
| | | */ |
| | | public static String string2Unicode(String string) { |
| | | StringBuffer unicode = new StringBuffer(); |
| | | for (int i = 0; i < string.length(); i++) { |
| | | // 取出每一个字符 |
| | | char c = string.charAt(i); |
| | | // 转换为unicode |
| | | unicode.append("\\u" + Integer.toHexString(c)); |
| | | } |
| | | return unicode.toString(); |
| | | } |
| | | |
| | | /** |
| | | * unicode 转字符串 |
| | | * |
| | | * @param unicode |
| | | * @return |
| | | * @author TaoNingBo |
| | | */ |
| | | public static String unicode2String(String unicode) { |
| | | StringBuffer string = new StringBuffer(); |
| | | String[] hex = unicode.split("\\\\u"); |
| | | for (int i = 1; i < hex.length; i++) { |
| | | // 转换出每一个代码点 |
| | | int data = Integer.parseInt(hex[i], 16); |
| | | // 追加成string |
| | | string.append((char) data); |
| | | } |
| | | return string.toString(); |
| | | } |
| | | |
| | | /** |
| | | * 字符串编码转换的实现方法 |
| | | * |
| | | * @param str |
| | | * 待转换编码的字符串 |
| | | * @param newCharset |
| | | * 目标编码 |
| | | * @return |
| | | * @throws UnsupportedEncodingException |
| | | */ |
| | | public static String changeCharset(String str, String newCharset) throws UnsupportedEncodingException { |
| | | if (str != null) { |
| | | // 用默认字符编码解码字符串。 |
| | | byte[] bs = str.getBytes(); |
| | | // 用新的字符编码生成字符串 |
| | | return new String(bs, newCharset); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 注: \n 回车( ) \t 水平制表符( ) \s 空格(\u0008) \r 换行( ) |
| | | * |
| | | * @param str |
| | | * @return |
| | | */ |
| | | public static String replaceBlank(String str) { |
| | | String dest = ""; |
| | | if (str != null) { |
| | | Pattern p = Pattern.compile("\\s*|\t|\r|\n"); |
| | | Matcher m = p.matcher(str); |
| | | dest = m.replaceAll(""); |
| | | } |
| | | return dest; |
| | | } |
| | | |
| | | /** |
| | | * 判断该字符串不能为空 |
| | | * |
| | | * @param str |
| | | * @return |
| | | * @author TaoNingBo |
| | | */ |
| | | public static boolean isNotEmpty(Object str) { |
| | | return !isEmpty(str); |
| | | } |
| | | |
| | | |
| | | public static boolean isNotEmptyUndefined(Object str) { |
| | | return !isEmpty(str) && !str.toString().equals("undefined"); |
| | | } |
| | | |
| | | /** |
| | | * 字符串编码转换的实现方法 |
| | | * |
| | | * @param str |
| | | * 待转换编码的字符串 |
| | | * @param oldCharset |
| | | * 原编码 |
| | | * @param newCharset |
| | | * 目标编码 |
| | | * @return |
| | | * @throws UnsupportedEncodingException |
| | | */ |
| | | public static String changeCharset(String str, String oldCharset, String newCharset) throws UnsupportedEncodingException { |
| | | if (str != null) { |
| | | // 用旧的字符编码解码字符串。解码可能会出现异常。 |
| | | byte[] bs = str.getBytes(oldCharset); |
| | | // 用新的字符编码生成字符串 |
| | | return new String(bs, newCharset); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 给手机号码加分割符 |
| | | * |
| | | * @param phone |
| | | * @return |
| | | * @author TaoNingBo |
| | | */ |
| | | public static String splitPhone(String phone) { |
| | | if (isNotEmpty(phone)) { |
| | | String strone = phone.substring(0, 3); |
| | | String strtwo = phone.substring(strone.length(), 7); |
| | | String strthree = phone.substring(strtwo.length() + strone.length(), phone.length()); |
| | | return strone + "-" + strtwo + "-" + strthree; |
| | | } |
| | | return ""; |
| | | } |
| | | |
| | | /** |
| | | * 非空判断 |
| | | * |
| | | * @param str |
| | | * @return |
| | | * @author TaoNingBo |
| | | */ |
| | | public static boolean isEmpty(Object str) { |
| | | return str == null || str.toString().length() == 0 || str.equals("") || str.toString().matches("\\s*"); |
| | | } |
| | | |
| | | /** |
| | | * 把米转换成公里 |
| | | * |
| | | * @param km |
| | | * @return |
| | | * @author TaoNingBo |
| | | */ |
| | | public static Double kmTransKilo(Integer m) { |
| | | return Math.round(m / 100d) / 10d; |
| | | } |
| | | |
| | | /** |
| | | * 将List<{@link Object}>转换成List<{@link T}> |
| | | * |
| | | * @param list |
| | | * 将要转换的对象 |
| | | * @param clazs |
| | | * 需要转换的泛型对象 |
| | | * @return |
| | | * @author TaoNingBo |
| | | */ |
| | | @SuppressWarnings("unchecked") |
| | | public static <T> List<T> fromToObject(List<?> list, Class<T> clazs) { |
| | | List<T> t = new ArrayList<T>(); |
| | | for (Object object : list) { |
| | | t.add((T) object); |
| | | } |
| | | return t; |
| | | } |
| | | |
| | | /** |
| | | * 生成 uuid, 即用来标识一笔单,也用做 nonce_str |
| | | * @return |
| | | */ |
| | | public static String generateUUID() { |
| | | return UUID.randomUUID().toString().replaceAll("-", "").substring(0, 32); |
| | | } |
| | | |
| | | /** |
| | | * 将List<{@link Object}>转换成List<{@link Map<String, Object>}> |
| | | * |
| | | * @param list |
| | | * @return |
| | | * @author TaoNingBo |
| | | */ |
| | | @SuppressWarnings("unchecked") |
| | | public static List<Map<String, Object>> fromToObject_M(List<?> list) { |
| | | List<Map<String, Object>> t = new ArrayList<Map<String, Object>>(); |
| | | for (Object object : list) { |
| | | t.add((Map<String, Object>) object); |
| | | } |
| | | return t; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.ruoyi.member.util; |
| | | |
| | | public class TemplateData { |
| | | private String value; |
| | | private String color; |
| | | public TemplateData(String value,String color){ |
| | | this.value = value; this.color = color; |
| | | } |
| | | public String getValue() { |
| | | return value; |
| | | } |
| | | public void setValue(String value) { |
| | | this.value = value; |
| | | } |
| | | public String getColor() { |
| | | return color; |
| | | } |
| | | public void setColor(String color) { |
| | | this.color = color; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.ruoyi.member.util; |
| | | |
| | | import java.util.Map; |
| | | |
| | | public class TemplateMessage { |
| | | private String touser; |
| | | // 用户OpenID |
| | | private String template_id; //模板消息ID |
| | | |
| | | private String url;//URL置空,在发送后,点模板消息进入一个空白页面(ios),或无法点击(android)。 |
| | | private String topcolor; //标题颜色 private |
| | | Map<String, TemplateData> templateData; //模板详细信息 |
| | | public String getTouser() { |
| | | return touser; |
| | | } |
| | | public void setTouser(String touser) { |
| | | this.touser = touser; |
| | | } |
| | | public String getTemplate_id() { |
| | | return template_id; |
| | | } |
| | | public void setTemplate_id(String template_id) { |
| | | this.template_id = template_id; |
| | | } |
| | | public String getUrl() { |
| | | return url; |
| | | } |
| | | public void setUrl(String url) { |
| | | this.url = url; |
| | | } |
| | | public String getTopcolor() { |
| | | return topcolor; |
| | | } |
| | | public void setTopcolor(String topcolor) { |
| | | this.topcolor = topcolor; |
| | | } |
| | | public Map<String, TemplateData> getTemplateData() { |
| | | return templateData; |
| | | } |
| | | public void setTemplateData(Map<String, TemplateData> templateData) { |
| | | this.templateData = templateData; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.ruoyi.member.util; |
| | | |
| | | import java.io.BufferedReader; |
| | | import java.io.InputStream; |
| | | import java.io.InputStreamReader; |
| | | import java.io.OutputStream; |
| | | import java.net.ConnectException; |
| | | import java.net.URL; |
| | | |
| | | import javax.net.ssl.HttpsURLConnection; |
| | | import javax.net.ssl.SSLContext; |
| | | import javax.net.ssl.SSLSocketFactory; |
| | | import javax.net.ssl.TrustManager; |
| | | |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | |
| | | public class WX_HttpsUtil { |
| | | private static Logger log = LoggerFactory.getLogger(WX_HttpsUtil.class); /** |
| | | * 发送https请求 |
| | | * @param requestUrl 请求地址 |
| | | * @param requestMethod 请求方式(GET、POST) |
| | | * @param outputStr 提交的数据 |
| | | * @return JSONObject(通过JSONObject.get(key)的方式获取json对象的属性值) |
| | | */ public static JSONObject httpsRequest(String requestUrl, String requestMethod, String outputStr) { |
| | | JSONObject jsonObject = null; |
| | | try { |
| | | // 创建SSLContext对象,并使用我们指定的信任管理器初始化 |
| | | TrustManager[] tm = { |
| | | new MyX509TrustManager() |
| | | }; |
| | | SSLContext sslContext = SSLContext.getInstance("SSL", "SunJSSE"); |
| | | sslContext.init(null, tm, new java.security.SecureRandom()); |
| | | // 从上述SSLContext对象中得到SSLSocketFactory对象 |
| | | SSLSocketFactory ssf = sslContext.getSocketFactory(); |
| | | URL url = new URL(requestUrl); |
| | | HttpsURLConnection conn = (HttpsURLConnection) url.openConnection(); |
| | | conn.setSSLSocketFactory(ssf); conn.setDoOutput(true); |
| | | conn.setDoInput(true); |
| | | conn.setUseCaches(false); |
| | | // 设置请求方式(GET/POST) |
| | | conn.setRequestMethod(requestMethod); |
| | | // 当outputStr不为null时向输出流写数据 |
| | | if (null != outputStr) { |
| | | OutputStream outputStream = conn.getOutputStream(); |
| | | // 注意编码格式 |
| | | outputStream.write(outputStr.getBytes("UTF-8")); |
| | | outputStream.close(); |
| | | } |
| | | // 从输入流读取返回内容 |
| | | InputStream inputStream = conn.getInputStream(); |
| | | InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "utf-8"); |
| | | BufferedReader bufferedReader = new BufferedReader(inputStreamReader); |
| | | String str = null; StringBuffer buffer = new StringBuffer(); |
| | | while ((str = bufferedReader.readLine()) != null) |
| | | { buffer.append(str); |
| | | } |
| | | // 释放资源 |
| | | bufferedReader.close(); |
| | | inputStreamReader.close(); |
| | | inputStream.close(); |
| | | inputStream = null; |
| | | conn.disconnect(); |
| | | jsonObject = JSONObject.parseObject(buffer.toString()); |
| | | } catch (ConnectException ce) |
| | | { |
| | | log.error("连接超时:{}", ce); |
| | | } catch (Exception e) |
| | | { |
| | | log.error("https请求异常:{}", e); |
| | | } |
| | | return jsonObject; |
| | | } |
| | | } |
New file |
| | |
| | | package com.ruoyi.member.util; |
| | | |
| | | import java.util.Map; |
| | | |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | |
| | | public class WX_TemplateMsgUtil { |
| | | private static Logger log = LoggerFactory.getLogger(WX_TemplateMsgUtil.class); |
| | | |
| | | /** |
| | | * 封装模板详细信息 |
| | | * |
| | | * @return |
| | | */ |
| | | public static JSONObject packJsonmsg(Map<String, TemplateData> param) { |
| | | JSONObject json = new JSONObject(); |
| | | for (Map.Entry<String, TemplateData> entry : param.entrySet()) { |
| | | JSONObject keyJson = new JSONObject(); |
| | | TemplateData dta = entry.getValue(); |
| | | keyJson.put("value", dta.getValue()); |
| | | keyJson.put("color", dta.getColor()); |
| | | json.put(entry.getKey(), keyJson); |
| | | } |
| | | return json; |
| | | } |
| | | |
| | | /** |
| | | * 根据模板的编号 新增并获取模板ID |
| | | * |
| | | * @param templateSerialNumber |
| | | * 模板库中模板的 "编号" |
| | | * @return 模板ID |
| | | */ |
| | | public static String getWXTemplateMsgId(String templateSerialNumber,String access_token) { |
| | | String tmpurl = "https://api.weixin.qq.com/cgi-bin/template/api_add_template?access_token=" |
| | | + access_token; |
| | | JSONObject json = new JSONObject(); |
| | | json.put("template_id_short", templateSerialNumber); |
| | | JSONObject result = WX_HttpsUtil.httpsRequest(tmpurl, "POST", json.toString()); |
| | | JSONObject resultJson = new JSONObject(result); |
| | | String errmsg = (String) resultJson.get("errmsg"); |
| | | log.info("获取模板编号返回信息:" + errmsg); |
| | | if (!"ok".equals(errmsg)) { |
| | | return "error"; |
| | | } |
| | | String templateId = (String) resultJson.get("template_id"); |
| | | return templateId; |
| | | } |
| | | |
| | | /** |
| | | * 根据模板ID 删除模板消息 |
| | | * @param templateId 模板ID |
| | | * @return |
| | | */ public static String deleteWXTemplateMsgById(String templateId,String access_token){ |
| | | String tmpurl = "https://api.weixin.qq.com/cgi-bin/template/del_private_template?access_token="+ access_token; |
| | | JSONObject json = new JSONObject(); json.put("template_id", templateId); |
| | | try{ |
| | | JSONObject result = WX_HttpsUtil.httpsRequest(tmpurl, "POST", json.toString()); |
| | | JSONObject resultJson = new JSONObject(result); |
| | | log.info("删除"+templateId+"模板消息,返回CODE:"+ resultJson.get("errcode")); |
| | | String errmsg = (String) resultJson.get("errmsg"); |
| | | if(!"ok".equals(errmsg)){ |
| | | return "error"; |
| | | } |
| | | }catch(Exception e){ |
| | | e.printStackTrace(); |
| | | } return "success"; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 发送微信消息(模板消息) |
| | | * @param touser 用户 OpenID |
| | | * @param templatId 模板消息ID |
| | | * @param clickurl URL置空,则在发送后,点击模板消息会进入一个空白页面(ios),或无法点击(android)。 |
| | | * @param topcolor 标题颜色 |
| | | * @param data 详细内容 |
| | | * @return |
| | | */ public static String sendWechatMsgToUser(String touser, String templatId, String clickurl, String topcolor, JSONObject data,String access_token) { |
| | | String tmpurl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+ access_token; |
| | | JSONObject json = new JSONObject(); |
| | | json.put("touser", touser); |
| | | json.put("template_id", templatId); |
| | | json.put("url", clickurl); json.put("topcolor", topcolor); |
| | | json.put("data", data); |
| | | try{ |
| | | JSONObject result = WX_HttpsUtil.httpsRequest(tmpurl, "POST", json.toString()); |
| | | JSONObject resultJson = new JSONObject(result); |
| | | log.info("发送微信消息返回信息:" + resultJson.get("errcode")); |
| | | String errmsg = (String) resultJson.get("errmsg"); |
| | | if(!"ok".equals(errmsg)){ |
| | | //如果为errmsg为ok,则代表发送成功,公众号推送信息给用户了。 |
| | | return "error"; |
| | | } |
| | | }catch(Exception e){ |
| | | e.printStackTrace(); |
| | | return "error"; }finally { |
| | | if(templatId!=null) { |
| | | //删除新增的 微信模板 |
| | | deleteWXTemplateMsgById(templatId,access_token); |
| | | } |
| | | } return "success"; |
| | | } |
| | | } |
| | | |
New file |
| | |
| | | package com.ruoyi.member.util; |
| | | |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | |
| | | import com.alibaba.fastjson.JSONException; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | |
| | | public class WX_TokenUtil { |
| | | private static String appid = "wx742b6a65ca132418"; |
| | | private static String appSecret = "5db469c7cb8ea798a7a8e6bc9ce72bab"; |
| | | |
| | | private static Logger log = LoggerFactory.getLogger(WX_TokenUtil.class); /** |
| | | * 获得微信 AccessToken |
| | | * access_token是公众号的全局唯一接口调用凭据,公众号调用各接口时都需使用access_token。 |
| | | * 开发者需要access_token的有效期目前为2个小时,需定时刷新,重复获取将导致上次获取 |
| | | * 的access_token失效。 |
| | | * (此处我是把token存在Redis里面了) |
| | | */ public static String getWXToken(String access_token) { |
| | | if(access_token == null || access_token.equals("")){ |
| | | String tokenUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+ appid+"&secret="+ appSecret; |
| | | JSONObject jsonObject = WX_HttpsUtil.httpsRequest(tokenUrl, "GET", null); |
| | | if (null != jsonObject) { |
| | | try { |
| | | String access_token1=jsonObject.getString("access_token").toString(); |
| | | return access_token1; |
| | | } catch (JSONException e) { |
| | | access_token = null; |
| | | // 获取token失败 |
| | | log.error("获取token失败 errcode:{} errmsg:{}", jsonObject.getInteger("errcode"), jsonObject.getString("errmsg")); |
| | | } |
| | | } |
| | | } |
| | | return access_token; |
| | | } |
| | | } |
New file |
| | |
| | | package com.ruoyi.member.util; |
| | | |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | |
| | | public class WX_UserUtil { |
| | | private static Logger log = LoggerFactory.getLogger(WX_UserUtil.class); /** |
| | | * 根据微信openId 获取用户是否订阅 |
| | | * @param openId 微信openId |
| | | * @return 是否订阅该公众号标识 |
| | | */ public static Integer subscribeState(String openId,String access_token) |
| | | { |
| | | String tmpurl = "https://api.weixin.qq.com/cgi-bin/user/info?access_token="+access_token +"&openid="+openId; JSONObject result = WX_HttpsUtil.httpsRequest(tmpurl, "GET",null); |
| | | JSONObject resultJson = new JSONObject(result); |
| | | log.error("获取用户是否订阅 errcode:{} errmsg:{}", resultJson.getInteger("errcode"), resultJson.getString("errmsg")); String errmsg = (String) resultJson.get("errmsg"); |
| | | if(errmsg==null){ |
| | | //用户是否订阅该公众号标识(0代表此用户没有关注该公众号 1表示关注了该公众号)。 |
| | | Integer subscribe = (Integer) resultJson.get("subscribe"); |
| | | return subscribe; |
| | | } |
| | | return -1; |
| | | } |
| | | } |
| | |
| | | import com.ruoyi.order.util.tencent.common.XMLParser; |
| | | import com.ruoyi.order.util.tencent.protocol.AppPayReqData; |
| | | import com.ruoyi.order.util.tencent.protocol.UnifiedorderReqData; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | |
| | | Logger log = LoggerFactory.getLogger(getClass()); |
| | | @ResponseBody |
| | | @RequestMapping("/getPayInfo") |
| | | @ApiOperation(value = "获取支付信息") |
| | | public R<Map<String, Object>> getPayInfo(Integer uid, Integer type, String subject, String body, String orderID, |
| | | HttpServletRequest request) { |
| | | try { |
| | |
| | | wrapper.eq(OrderAuctionBond::getAuctionSalesroomId, orderAuctionBondDTO.getAuctionSalesroomId()); |
| | | List<OrderAuctionBond> orderAuctionBondList = iOrderAuctionBondService.list(wrapper); |
| | | for (OrderAuctionBond orderAuctionBond : orderAuctionBondList) { |
| | | |
| | | LambdaQueryWrapper<Paylog> wrapper1 = Wrappers.lambdaQuery(); |
| | | wrapper1.notIn(Paylog::getOutTradeNo, orderAuctionBond.getOrderNo()); |
| | | wrapper1.eq(Paylog::getOutTradeNo, orderAuctionBond.getOrderNo()); |
| | | wrapper1.last("limit 1"); |
| | | Paylog paylog = iPaylogService.getOne(wrapper1); |
| | | |
| | | if (paylog.getPayType() == 1) {//支付宝 |
| | | boolean bo = paylogServiceImpl.refundForAlipay(paylog.getOutTradeNo(), paylog.getTradeNo(), orderAuctionBond.getBond().doubleValue()); |
| | | if (!bo) { |
| | |
| | | return paylogServiceImpl.alipay("1", subject, body, price, request); |
| | | } else { |
| | | // 微信预下单 |
| | | return wxpay(1, "1", body, price, request); |
| | | return paylogServiceImpl.wxpay(1, "1", body, price, request); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | |
| | | import com.alipay.api.domain.AlipayTradeAppPayModel; |
| | | import com.alipay.api.request.AlipayTradeAppPayRequest; |
| | | import com.alipay.api.response.AlipayTradeAppPayResponse; |
| | | import com.alipay.config.AlipayConfig; |
| | | import com.ruoyi.order.util.alipay.config.AlipayConfig; |
| | | |
| | | |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.util.HashMap; |
New file |
| | |
| | | #是否开启调试true |
| | | debug = false |
| | | |
| | | |
| | | |
| | | ## 支付宝配置文件 ## |
| | | |
| | | # 商户收款支付宝账号 |
| | | seller_email = 962295261@qq.com |
| | | # 商户私钥 |
| | | private_key = MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCh8gD6Up6ekrCgX5jKW5dBpieAJETViJ2pjTlxAsUq6XYsuxDPcAQDtBXPwhnIMsoMzTvgjRVS632h2nIDVOPEeW1kOkNor4mnchYowDCh+nt9VbI+2N0RVAPGqlNELAlvvmpZiUCupWHdZIco/UHYdWWLAsK+8wjT1LgVGOGU5Q9+98yCsxfeWkfFlgRM/FwhaYUkfgudujYQCf6GxhCNMci8iylreQMUcb8gaF4bjcLPyYAPCiINA5bq8GJwQG+CAqpMOXzFcRnyvAsUAn0mctfPpb6Kp2vUF5Yh2dQMpcSQMkH7arqS0jmCTy0v1/8nQLlKVQEXrTrx44f3/wB9AgMBAAECggEAHYn456/+Qspa8UW+ptqCAnV+Kv9ylshuiai624Q31pXy+kG81TmHYe2NNPIgpcWt2RvuWg0h4JgXuFgSB82KJiJH88o01Xl/UE2dAR3dQQ5hTAE/m/sOh8SdU7VprruhlQJUf7RrWe/MpAdcJ/vZ8NOpC+wa/Z1y9MCOOzromrHJaxqJeNInj5asJRpet0mCbXi6yduaF3dMwwyCP/yL0vyjQEb5vyPic7Vi1tzhnaUG/kEM3TYv/BqY2wW5AGUdtoOA6ao+eR1lyAqSPmL81b1ytYJv83FZzpv7IXwp6kDbcbSNYcycT9uzxOxzWIeolX77QERCjQYBi8s65KjuuQKBgQD7dv58c58yHm3uwKuA6pdIgk0uPQ1JEmCYAFT73YNEX7uL4fRJuf4mJuuMSlSM9eKuDeGahsia5jiNoxI4I6xqPJ4crJZX3M/P7zWSEdji6a+2+5uqtpWuA/7lPfmy/CuPdRYqoepELoZdYh0jmQrYXzoWarL51teGXkiS+/v28wKBgQCk3bNmhBmACCyDmQ6UpwxAZs5huknT6SmkWZsc3PDSyJXXfxkJR5EvxXsX+djfGUbB8B6RUjlHXsK03ojNhmW31z+lMseBLhq8+9nbtooo7yWLPhBimM5ta5O07XwW0aDC/hILpjZG7Nc9S6oAOx8xCTlKBAG83xU2GfL1rAzmzwKBgQD3zuQrMKYJdgNP7X8VpBlB02bL0k5tXDbklC8rpbfegZkI2LssjKXwYxptPjLkVsv0Sqmw5nJ6c7X3nmQt/rnCV8pY55uhKnGAsHNSZ1QdCb2nzXwyV4xZ2IYw00pnICqtTO1zRezfFBpFnJKqqf8OC4nq3WtS2m26dN+AOeKsEQKBgAruK+u7DFnBsPnUlvPiE1zdtAckq6piBgHAcxk5yLmg1NZhtc44sXaCWEPhq7A248sN2Wj3E5cYwD3vlxBRPcMvgSe5syJsZRdsdygq9QP7vvh5V+rBiMYWYMeZCyYUJd1nrNia33RaVXbZ4l57jPjaTLMMivTzsVtR4xrIml5fAoGAafZXXMmHRPdoMPbuZv19OBZYHFLy4eVihBJML9WYpPJS0wTdvcsrIWsdfFvJgM5ofgsbZ03gy4dDYp8jq/4RaYcsJ8PBW1ETuyf/Kw8+BglxX1NEDcVqniW9pHd0FRahn//h0cBK0iAfcs+VtIN2fcCzUmBfx7iegusq0o6eJfU= |
| | | # 支付宝公钥 |
| | | ali_public_key = MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAo3EoPQOXMlLmsCev3M3SAtu09YSPld7R0BFjaLBImX3oMueU8vekJQ1dDcJjYPAfaK+zlfbFqHoWWr2vft7jieQe5dXCS4vOm50Uhl5CfyrEcKsj9CMVX8aDzfVRSvItx1yG2o3jq42YlLV09FACeTP6NvDDQ+oaG8TXUzFkAv4wRfOUX/r/RKnXG5UZXhIUx7+A9qqDe/h1f0jbq6Q8n0Gxj0p0fhMOZwPdCR1Lota288SdgsT3oCypN5lzWrbhIhxAldsvMuEeAhszqN+DO37tc3dvqI1UGnXtvQz/bzBeTUpy71optvNNVq19WHj/7SWrYm8WStZNz5LzAX218QIDAQAB |
| | | |
| | | # 支付宝回调地址 |
| | | notify_url = http://116.63.172.131:8088/api/pay/alipay/notify |
| | | # 签约的appid |
| | | app_id = 2021001161670285 |
| | | |
| | | |
| | | ## 支付宝配置文件 ## |
| | | |
| | | ## 微信支付配置文件(1)-start 0398bce360f3f5d9fbcce40326929639 |
| | | # 微信开发平台(应用APPID) |
| | | #以前的wx74f8aea529dc99d7 |
| | | |
| | | appID = wx24b9abadcc524e29 |
| | | |
| | | # 微信支付分配的商户号ID(微信支付商户号) |
| | | mchID = 1600685974 |
| | | |
| | | # 公众号的商户号 |
| | | GmchID = 1600685974 |
| | | |
| | | # 应用对应的密钥(商户平台开发设置) |
| | | key = E10ADC3949BA59ABBE56E057F20F883E |
| | | |
| | | # 微信回调地址 |
| | | wx_notify_url = http://116.63.172.131:8088/api/pay/wxpay/notify |
| | | |
| | | # 没有公众号支付所以没有后面的参数配置 |
| | | # 公众号对应的密钥(商户平台开发设置) |
| | | key_2 = ZTlyynxl24490918687091970bianhao |
| | | |
| | | # 公众号的APPID |
| | | GappID = wx742b6a65ca132418 |
| | | #公众号的appSecret |
| | | appSecret = 1baf1d22f695f3a9aa9f59934bcc94fe |
| | | |