|  |  |  | 
|---|
|  |  |  | import com.doumee.core.constants.ResponseStatus; | 
|---|
|  |  |  | import com.doumee.core.exception.BusinessException; | 
|---|
|  |  |  | import com.doumee.core.utils.DateUtil; | 
|---|
|  |  |  | import com.doumee.core.utils.HttpsUtil; | 
|---|
|  |  |  | import com.doumee.core.utils.ID; | 
|---|
|  |  |  | import com.doumee.core.utils.ImageDesignerUtil; | 
|---|
|  |  |  | import com.doumee.dao.business.RefundMapper; | 
|---|
|  |  |  | import com.doumee.dao.business.TransactionsMapper; | 
|---|
|  |  |  | import com.doumee.dao.business.model.Bikes; | 
|---|
|  |  |  | import com.doumee.dao.business.model.Locks; | 
|---|
|  |  |  | import com.doumee.dao.business.model.Refund; | 
|---|
|  |  |  | import com.doumee.dao.business.model.Transactions; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.doumee.dao.system.model.SystemDictData; | 
|---|
|  |  |  | import com.wechat.pay.java.service.refund.model.AmountReq; | 
|---|
|  |  |  | import com.wechat.pay.java.service.refund.model.CreateRequest; | 
|---|
|  |  |  | import com.wechat.pay.java.service.refund.model.QueryByOutRefundNoRequest; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import okhttp3.OkHttpClient; | 
|---|
|  |  |  | import okhttp3.Request; | 
|---|
|  |  |  | import okhttp3.Response; | 
|---|
|  |  |  | import org.apache.commons.io.FileUtils; | 
|---|
|  |  |  | import org.apache.commons.lang3.StringUtils; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.io.ByteArrayInputStream; | 
|---|
|  |  |  | import java.io.File; | 
|---|
|  |  |  | import java.io.InputStream; | 
|---|
|  |  |  | import java.io.*; | 
|---|
|  |  |  | import java.math.BigDecimal; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  | 
|---|
|  |  |  | amountReq.setCurrency("CNY"); | 
|---|
|  |  |  | request.setAmount(amountReq); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | log.error("=============="+JSONObject.toJSONString(request)); | 
|---|
|  |  |  | com.wechat.pay.java.service.refund.model.Refund response = WxMiniConfig.refundService.create(request); | 
|---|
|  |  |  | log.error("=============="+JSONObject.toJSONString(response)); | 
|---|
|  |  |  | if ("SUCCESS".equals(response.getStatus().name()) | 
|---|
|  |  |  | || "PROCESSING".equals(response.getStatus().name()) ) { | 
|---|
|  |  |  | return  true; | 
|---|
|  |  |  | 
|---|
|  |  |  | throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,退款申请失败!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @Transactional(rollbackFor = {BusinessException.class,Exception.class}) | 
|---|
|  |  |  | public com.wechat.pay.java.service.refund.model.Refund isSuucessRefund(String outTradeNo) { | 
|---|
|  |  |  | // 发送退款请求 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | QueryByOutRefundNoRequest request = new QueryByOutRefundNoRequest(); | 
|---|
|  |  |  | request.setOutRefundNo(outTradeNo); | 
|---|
|  |  |  | request.setSubMchid(WxMiniConfig.wxProperties.getSubMchId()); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | log.error("=============="+JSONObject.toJSONString(request)); | 
|---|
|  |  |  | com.wechat.pay.java.service.refund.model.Refund response = WxMiniConfig.refundService.queryByOutRefundNo(request); | 
|---|
|  |  |  | log.error("=============="+JSONObject.toJSONString(response)); | 
|---|
|  |  |  | if ("SUCCESS".equals(response.getStatus().name()) | 
|---|
|  |  |  | || "PROCESSING".equals(response.getStatus().name()) ) { | 
|---|
|  |  |  | return  response; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return  null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | public Refund wxRefundOld(RefundDTO refundDTO) { | 
|---|
|  |  |  | // 发送退款请求 | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static void main(String[] args) throws IOException { | 
|---|
|  |  |  | /* InputStream inputStream = HttpsUtil.postJson("https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=75_W8lx5-bp9WEo69pQ6hvN70fJJJCNSRby6Wi6z_R9G7Sd5GMdY7ZT8Zq3PrKWrFBq92utfgqu3P8iw1NOvJNfyZssEYCy6k94Wch-GQNXcarSV65gowLk-SA9bncWTJbAGAHEU", "{\"check_path\":false,\"is_hyaline\":false,\"page\":\"pages/index/index\",\"scene\":\"1993/90\",\"env_version\":\"trial\"}"); | 
|---|
|  |  |  | File file = new File("D://test.png"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //定义一个用于读取InputStream数据的byte数组 | 
|---|
|  |  |  | byte[] buffer = new byte[1024]; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //输出流,用于写入文件 | 
|---|
|  |  |  | FileOutputStream outputStream = new FileOutputStream(file); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //循环读取数据并将其写入文件中 | 
|---|
|  |  |  | int length; | 
|---|
|  |  |  | while ((length = inputStream.read(buffer)) > 0) { | 
|---|
|  |  |  | outputStream.write(buffer, 0, length); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //关闭InputStream和OutputStream | 
|---|
|  |  |  | inputStream.close(); | 
|---|
|  |  |  | outputStream.close();*/ | 
|---|
|  |  |  | Map<String,Object> body = new HashMap<>(); | 
|---|
|  |  |  | // 场景码,与前端约定,最终是需要前端解析 | 
|---|
|  |  |  | body.put("scene",   "1992/41" ); | 
|---|
|  |  |  | // 正式版为 "release",体验版为 "trial",开发版为 "develop"。默认是正式版。 | 
|---|
|  |  |  | //        body.put("env_version", "release"); | 
|---|
|  |  |  | body.put("env_version", "trial"); | 
|---|
|  |  |  | // 透明,根据你的场景自行设置body参数 | 
|---|
|  |  |  | body.put("is_hyaline",false); | 
|---|
|  |  |  | body.put("check_path", false); | 
|---|
|  |  |  | body.put("page","pages/index/index"); | 
|---|
|  |  |  | OkHttpClient client = new OkHttpClient().newBuilder().build(); | 
|---|
|  |  |  | okhttp3.MediaType mediaType = okhttp3.MediaType.parse("application/json"); | 
|---|
|  |  |  | log.info("=========================================="+JSONObject.toJSONString(body)); | 
|---|
|  |  |  | okhttp3.RequestBody requestBody = okhttp3.RequestBody.create(mediaType, JSONObject.toJSONString(body)); | 
|---|
|  |  |  | Request request = new Request.Builder().url("https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=75_MppLyM-Fy1rWPbJE8ccXfy90Afg_3wdENqKBEshglyyARP3egjvsti3agoaZJ0UVKHh_wwuIDcbu41ptPKleUcaD1vDRi4BrH8oN8TEHPTUCb1Kcp6ZoMJNNWScZKChAIAHSK").method("POST", requestBody).build(); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | Response response = client.newCall(request).execute(); | 
|---|
|  |  |  | if (response.isSuccessful()) { | 
|---|
|  |  |  | InputStream inputStream = new ByteArrayInputStream(response.body().bytes()); | 
|---|
|  |  |  | String nowDate = DateUtil.getNowShortDate(); | 
|---|
|  |  |  | File file = new File("D://test1.png"); | 
|---|
|  |  |  | FileUtils.copyInputStreamToFile(inputStream,file); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 生成小程序码 | 
|---|
|  |  |  | * https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/qr-code/getUnlimitedQRCode.html | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public void generateWXMiniCode(Locks locks,SystemDictData systemDictData,String prePath,String path){ | 
|---|
|  |  |  | public void generateWXMiniCode(Locks locks,String token,String prePath,String path){ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(Objects.isNull(systemDictData)){ | 
|---|
|  |  |  | if(Objects.isNull(token)){ | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String url =  "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token="+ token; | 
|---|
|  |  |  | String release =   systemDictDataBiz.queryByCode(Constants.MINI_PROGRAMME,Constants.MINI_PROGRAMME_REALEASE).getCode(); | 
|---|
|  |  |  | //生成图片上传OSS | 
|---|
|  |  |  | Map<String,Object> body = new HashMap<>(); | 
|---|
|  |  |  | // 场景码,与前端约定,最终是需要前端解析 | 
|---|
|  |  |  | body.put("scene", locks.getSiteId() + "/" +locks.getCode() ); | 
|---|
|  |  |  | // 正式版为 "release",体验版为 "trial",开发版为 "develop"。默认是正式版。 | 
|---|
|  |  |  | body.put("env_version", "release"); | 
|---|
|  |  |  | //        body.put("env_version", "release"); | 
|---|
|  |  |  | body.put("env_version", StringUtils.defaultString(release, "release")); | 
|---|
|  |  |  | // 透明,根据你的场景自行设置body参数 | 
|---|
|  |  |  | body.put("is_hyaline", false); | 
|---|
|  |  |  | body.put("check_path", false); | 
|---|
|  |  |  | body.put("width", 290); | 
|---|
|  |  |  | body.put("page","pages/index/index"); | 
|---|
|  |  |  | log.info("=========================================="+url+"\n"+JSONObject.toJSONString(body)); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | InputStream inputStream  =HttpsUtil.postJson(url,JSONObject.toJSONString(body));; | 
|---|
|  |  |  | if (inputStream !=null) { | 
|---|
|  |  |  | String nowDate = DateUtil.getNowShortDate(); | 
|---|
|  |  |  | String name =locks.getSiteId()+"-"+locks.getCode()+"-"+nowDate+".png"; | 
|---|
|  |  |  | String fileName =prePath+path+"/"+name; | 
|---|
|  |  |  | //                File file = new File(prePath+path,locks.getSiteId()+"-"+locks.getCode()+"-"+nowDate+".png"); | 
|---|
|  |  |  | //                FileUtils.copyInputStreamToFile(inputStream,file); | 
|---|
|  |  |  | if(ImageDesignerUtil.graphicsGenerationIs(locks.getSiteId()+"/"+locks.getCode(),inputStream,fileName)){ | 
|---|
|  |  |  | locks.setInfo(name); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | public void generateEbikeWXMiniCode(Bikes bikes, String token, String prePath, String path){ | 
|---|
|  |  |  | if(Objects.isNull(token)){ | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String url =  "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token="+ token; | 
|---|
|  |  |  | String release =   systemDictDataBiz.queryByCode(Constants.MINI_PROGRAMME,Constants.MINI_PROGRAMME_REALEASE).getCode(); | 
|---|
|  |  |  | //生成图片上传OSS | 
|---|
|  |  |  | Map<String,Object> body = new HashMap<>(); | 
|---|
|  |  |  | // 场景码,与前端约定,最终是需要前端解析 | 
|---|
|  |  |  | body.put("scene",  Constants.EBIKE_PREFIX +bikes.getCode() ); | 
|---|
|  |  |  | // 正式版为 "release",体验版为 "trial",开发版为 "develop"。默认是正式版。 | 
|---|
|  |  |  | //        body.put("env_version", "release"); | 
|---|
|  |  |  | body.put("env_version", StringUtils.defaultString(release, "release")); | 
|---|
|  |  |  | // 透明,根据你的场景自行设置body参数 | 
|---|
|  |  |  | body.put("is_hyaline", false); | 
|---|
|  |  |  | body.put("check_path", false); | 
|---|
|  |  |  | body.put("width", 290); | 
|---|
|  |  |  | body.put("page","pages/index/index"); | 
|---|
|  |  |  | log.info("=========================================="+url+"\n"+JSONObject.toJSONString(body)); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | InputStream inputStream  =HttpsUtil.postJson(url,JSONObject.toJSONString(body));; | 
|---|
|  |  |  | if (inputStream !=null) { | 
|---|
|  |  |  | String nowDate = DateUtil.getNowShortDate(); | 
|---|
|  |  |  | String name =Constants.EBIKE_PREFIX+bikes.getCode()+"-"+nowDate+".png"; | 
|---|
|  |  |  | String fileName =prePath+path+"/"+name; | 
|---|
|  |  |  | //                File file = new File(prePath+path,locks.getSiteId()+"-"+locks.getCode()+"-"+nowDate+".png"); | 
|---|
|  |  |  | //                FileUtils.copyInputStreamToFile(inputStream,file); | 
|---|
|  |  |  | if(ImageDesignerUtil.graphicsGenerationIs(bikes.getCode(),inputStream,fileName)){ | 
|---|
|  |  |  | bikes.setImgurl(name); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 生成小程序码 | 
|---|
|  |  |  | * https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/qr-code/getUnlimitedQRCode.html | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public void generateWXMiniCodeOld(Locks locks,SystemDictData systemDictData,String prePath,String path){ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(Objects.isNull(systemDictData)){ | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String release =   systemDictDataBiz.queryByCode(Constants.MINI_PROGRAMME,Constants.MINI_PROGRAMME_REALEASE).getCode(); | 
|---|
|  |  |  | //生成图片上传OSS | 
|---|
|  |  |  | Map<String,Object> body = new HashMap<>(); | 
|---|
|  |  |  | // 场景码,与前端约定,最终是需要前端解析 | 
|---|
|  |  |  | body.put("scene", locks.getSiteId() + "/" +locks.getCode() ); | 
|---|
|  |  |  | // 正式版为 "release",体验版为 "trial",开发版为 "develop"。默认是正式版。 | 
|---|
|  |  |  | //        body.put("env_version", "release"); | 
|---|
|  |  |  | body.put("env_version", StringUtils.defaultString(release, "release")); | 
|---|
|  |  |  | // 透明,根据你的场景自行设置body参数 | 
|---|
|  |  |  | body.put("is_hyaline", Boolean.FALSE.toString()); | 
|---|
|  |  |  | body.put("check_path", Boolean.FALSE.toString()); | 
|---|
|  |  |  | body.put("page","pages/index/index"); | 
|---|
|  |  |  | OkHttpClient client = new OkHttpClient().newBuilder().build(); | 
|---|
|  |  |  | okhttp3.MediaType mediaType = okhttp3.MediaType.parse("application/json"); | 
|---|
|  |  |  | okhttp3.RequestBody requestBody = okhttp3.RequestBody.create(mediaType, JSONObject.toJSONString(body)); | 
|---|
|  |  |  | log.info("=========================================="+JSONObject.toJSONString(body)); | 
|---|
|  |  |  | Request request = new Request.Builder().url("https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token="+systemDictData.getCode()).method("POST", requestBody).build(); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | Response response = client.newCall(request).execute(); | 
|---|