202506171541

This commit is contained in:
张潘 2025-06-17 15:41:15 +08:00
parent d729c52fcf
commit f495c1655f
7 changed files with 510 additions and 76 deletions

View File

@ -1895,9 +1895,9 @@ public class AppletController extends BaseController {
if (!(Boolean) userValidation.get("valid")) {
return error("用户未登录或token无效");
}
WechatPayUtil wechatPayUtil = new WechatPayUtil();
// 2. 调用微信支付统一下单
Map<String, Object> payResult = WechatPayUtil.unifiedOrder(params);
Map<String, Object> payResult = wechatPayUtil.unifiedOrder((String) params.get("openid"), (String) params.get("orderNo"), (int) params.get("totalFee"), (String) params.get("body"), (String) params.get("notifyUrl"), (String) params.get("attach"));
// 3. 返回结果
boolean success = (Boolean) payResult.get("success");
@ -1928,9 +1928,9 @@ public class AppletController extends BaseController {
if (!(Boolean) userValidation.get("valid")) {
return error("用户未登录或token无效");
}
WechatPayUtil wechatPayUtil = new WechatPayUtil();
// 2. 查询订单状态
Map<String, Object> queryResult = WechatPayUtil.queryOrder(orderNo, null);
Map<String, Object> queryResult = wechatPayUtil.queryOrder(orderNo, null);
// 3. 返回结果
boolean success = (Boolean) queryResult.get("success");
@ -1972,9 +1972,9 @@ public class AppletController extends BaseController {
if (!(Boolean) userValidation.get("valid")) {
return error("用户未登录或token无效");
}
WechatPayUtil wechatPayUtil = new WechatPayUtil();
// 2. 创建代付订单
Map<String, Object> payForResult = WechatPayUtil.createPayForOrder(params);
Map<String, Object> payForResult = wechatPayUtil.unifiedOrder(params.get("payerOpenid").toString(), params.get("orderNo").toString(),Integer.valueOf(params.get("totalFee").toString()), params.get("body").toString(), params.get("notifyUrl").toString(), params.get("remark").toString());
// 3. 返回结果
boolean success = (Boolean) payForResult.get("success");
@ -2001,8 +2001,9 @@ public class AppletController extends BaseController {
@PostMapping(value = "/api/pay/notify")
public String handlePayNotify(HttpServletRequest request) {
try {
WechatPayUtil wechatPayUtil = new WechatPayUtil();
// 1. 处理支付回调
Map<String, Object> notifyResult = WechatPayUtil.handlePayNotify(request);
Map<String, Object> notifyResult = wechatPayUtil.handlePayNotify(request);
// 2. 获取支付信息
boolean success = (Boolean) notifyResult.get("success");
@ -2052,9 +2053,9 @@ public class AppletController extends BaseController {
if (!(Boolean) userValidation.get("valid")) {
return error("用户未登录或token无效");
}
WechatPayUtil wechatPayUtil = new WechatPayUtil();
// 2. 申请退款
Map<String, Object> refundResult = WechatPayUtil.refund(params);
Map<String, Object> refundResult = wechatPayUtil.refund(params);
// 3. 返回结果
boolean success = (Boolean) refundResult.get("success");
@ -2093,9 +2094,9 @@ public class AppletController extends BaseController {
if (!(Boolean) userValidation.get("valid")) {
return error("用户未登录或token无效");
}
WechatPayUtil wechatPayUtil = new WechatPayUtil();
// 2. 企业付款
Map<String, Object> transferResult = WechatPayUtil.transferToUser(params);
Map<String, Object> transferResult = wechatPayUtil.transferToUser(params);
// 3. 返回结果
boolean success = (Boolean) transferResult.get("success");
@ -3070,6 +3071,36 @@ public class AppletController extends BaseController {
}
}
/**
* 小程序下单时用户订阅消息推送接口前端不传值后端返回固定结构
* @return 订阅消息推送ID分类结果
*/
@GetMapping("/api/public/massge/notice")
public Map<String, Object> subscribeMessageNotice() {
Map<String, Object> data = new HashMap<>();
data.put("make_success", Arrays.asList(
"YKnuTCAD-oEEhNGoI3LUVkAqNsykOMTcyrf71S9vev8",
"5lA-snytEPl25fBS7rf6rQi8Y0i5HOSdG0JMVdUnMcU"
));
data.put("pay_success", Arrays.asList(
"pv3cba-wPoinUbBZSskp0KpDNnJwrHqS0rvGBfDNQ1M"
));
data.put("integral", Arrays.asList(
"pv3cba-wPoinUbBZSskp0KpDNnJwrHqS0rvGBfDNQ1M"
));
data.put("worker", Arrays.asList(
"5lA-snytEPl25fBS7rf6rQi8Y0i5HOSdG0JMVdUnMcU"
));
Map<String, Object> result = new HashMap<>();
result.put("code", 200);
result.put("msg", "OK");
result.put("data", data);
return result;
}
/**
* 积分商品兑换接口
*
@ -4354,7 +4385,7 @@ public class AppletController extends BaseController {
Long productId = Long.valueOf(orderParams.get("product_id").toString());
Long addressId = Long.valueOf(orderParams.get("address_id").toString());
String makeTime = orderParams.get("make_time").toString();
Long num = Long.valueOf(orderParams.get("num").toString());
String sku = orderParams.get("sku") != null ? orderParams.get("sku").toString() : "";
// 5. 查询商品信息
@ -4368,7 +4399,9 @@ public class AppletController extends BaseController {
if (userAddress == null) {
return error("地址不存在");
}
//判断如果是商品就添加商品订单如果是服务就添加服务订单
if(serviceGoods.getType()==2){
Long num = Long.valueOf(orderParams.get("num").toString());
GoodsOrder goodsOrder = new GoodsOrder();
goodsOrder.setType(2);
goodsOrder.setMainOrderId("WX" + System.currentTimeMillis());
@ -4403,6 +4436,7 @@ public class AppletController extends BaseController {
order.setAddressId(addressId);
order.setSku(sku);
// 解析预约时间
String[] makeTimeArr = makeTime.split(" ");
if (makeTimeArr.length != 2) {
@ -4418,7 +4452,7 @@ public class AppletController extends BaseController {
return error("预约时间格式错误");
}
order.setNum(num); // 默认数量为1
order.setNum(1l); // 默认数量为1
order.setTotalPrice(serviceGoods.getPrice()); // 总价等于商品价格
order.setGoodPrice(serviceGoods.getPrice()); // 商品金额
order.setServicePrice(BigDecimal.ZERO); // 服务金额默认为0
@ -4428,6 +4462,7 @@ public class AppletController extends BaseController {
order.setIsAccept(0); // 0未接单
order.setIsComment(0); // 0未评价
order.setIsPause(1); // 0未暂停
order.setDeduction(new BigDecimal(0));
// 8. 生成订单号
String orderId = generateOrderId();
order.setOrderId(orderId);
@ -4445,6 +4480,46 @@ public class AppletController extends BaseController {
orderLog.setType(new BigDecimal(1.0));
orderLog.setContent(jsonObject.toString());
orderLogService.insertOrderLog(orderLog);
//完成订单的初步创建之后开始进行派单和发送订阅以及预约师傅的操作
//完成订单后的第一步向用户发送订阅消息
Order orderNewData= orderService.selectOrderById(order.getId());
String wxsendmsg=WXsendMsgUtil.sendMsgForUserInfo(user.getOpenid(), orderNewData, serviceGoods);
//第二步系统派单
Users worker = AppletControllerUtil.creatWorkerForOrder(orderNewData);
//第三步向师傅发送订阅消息
if(worker!=null){
//确定派单之后更新订单状态为已派单并添加订单日志记录
//修改订单状态为派单开始-------------------------------------------
orderNewData.setWorkerId(worker.getId());
orderNewData.setStatus(2l);
orderNewData.setIsPause(1);
orderNewData.setReceiveTime(new Date());
orderNewData.setReceiveType(3l);
orderNewData.setLogStatus(9);
JSONObject jSONObject =new JSONObject();
jSONObject.put("type",9);
orderNewData.setLogJson(jSONObject.toJSONString());
orderService.updateOrder(orderNewData);
OrderLog orderLognew = new OrderLog();
orderLognew.setOid(orderNewData.getId());
orderLognew.setOrderId(orderNewData.getOrderId());
orderLognew.setTitle("平台派单");
orderLognew.setType(new BigDecimal(1.1));
JSONObject jSONObject1 =new JSONObject();
jSONObject1.put("name","师傅收到派单信息");
orderLognew.setContent(jSONObject1.toJSONString());
orderLognew.setWorkerId(worker.getId());
orderLognew.setWorkerLogId(worker.getId());
orderLogService.insertOrderLog(orderLognew);
//修改订单状态为派单结束-------------------------------------------
//给师傅发送微信订阅消息进行通知需要他进行接单
WXsendMsgUtil.sendMsgForWorkerInfo(worker.getOpenid(), orderNewData, serviceGoods);
//第四步给师傅进行电话通知
YunXinPhoneUtilAPI.httpsAxbTransfer(worker.getPhone(), "404168");
}
System.out.println("wxsendmsg" + wxsendmsg);
return success("预约成功");
} else {
return error("预约失败,请稍后重试");
@ -4577,6 +4652,13 @@ public class AppletController extends BaseController {
order.setReceiveTime(new Date());
order.setIsAccept(1); // 1:已接单
order.setJsonStatus(2); // 服务进度2=接单
order.setLogStatus(9);
JSONObject json=new JSONObject();
json.put("type",1);
order.setLogJson(json.toJSONString());
//绑定号码
// 5. 写入日志
OrderUtil orderUtil = new OrderUtil();
orderUtil.SaveOrderLog(order);
@ -4903,7 +4985,7 @@ public class AppletController extends BaseController {
data.put("name", order.getName());
data.put("phone", order.getPhone());
data.put("address", address);
data.put("make_time", order.getMakeTime());
data.put("make_time", AppletControllerUtil.timeStamp2Date(order));
data.put("make_hour", order.getMakeHour());
data.put("num", order.getNum());
data.put("total_price", order.getTotalPrice());

View File

@ -2,17 +2,15 @@ package com.ruoyi.system.ControllerUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.ruoyi.system.domain.ServiceCate;
import com.ruoyi.system.domain.ServiceGoods;
import com.ruoyi.system.domain.Users;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.service.IServiceGoodsService;
import com.ruoyi.system.service.IUserAddressService;
import com.ruoyi.system.service.IUsersService;
import com.github.pagehelper.PageInfo;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* 小程序控制器工具类
@ -30,7 +28,11 @@ import java.util.Map;
* @version 1.0
*/
public class AppletControllerUtil {
private static final IUsersService usersService= SpringUtils.getBean(IUsersService.class);
private static final IUserAddressService userAddressService= SpringUtils.getBean(IUserAddressService.class);
// ============================== 统一响应处理方法 ==============================
/**
@ -2114,7 +2116,7 @@ public class AppletControllerUtil {
orderDetail.put("name", order.getName());
orderDetail.put("phone", order.getPhone());
orderDetail.put("address", order.getAddress());
orderDetail.put("make_time", order.getMakeTime());
orderDetail.put("make_time", AppletControllerUtil.timeStamp2Date(order));
orderDetail.put("make_hour", order.getMakeHour());
orderDetail.put("num", order.getNum());
@ -2358,6 +2360,28 @@ public class AppletControllerUtil {
return timeSlotList;
}
/**
* 订单生成给师傅派单
*
* @param order 订单主键
* @return 是否可用
*/
public static Users creatWorkerForOrder(Order order) {
GaoDeMapUtil gaoDeMapUtil = new GaoDeMapUtil();
UserAddress userAddress = userAddressService.selectUserAddressById(order.getAddressId());
// if (userAddress != null){
// String city = gaoDeMapUtil.getCityByLocation(userAddress.getLongitude(), userAddress.getLatitude());
// if (city != null){
//
// }else{
//
// }
// }
Users worker = usersService.selectUsersById(2l);
return worker;
}
/**
* 判断时间段是否可用
*
@ -2730,4 +2754,83 @@ public class AppletControllerUtil {
}
return resultMap;
}
//完成订单的初步创建之后开始进行派单和发送订阅以及预约师傅的操作
public static Map<String, Object> creatOrderTheNext(String imageUrl) {
Map<String, Object> imageData = new HashMap<>();
//第一步给客户发送订阅消息告诉客户预约成功
imageData.put("url", imageUrl);
imageData.put("thumb", imageUrl);
return imageData;
}
/**
* 发送微信小程序订阅消息自动获取accessToken
* @param touser 接收者用户的openid
* @param templateId 订阅消息模板ID
* @param page 跳转页面路径可选可为null
* @param data 模板内容{"thing1":{"value":"内容"}}
* @return 微信接口响应字符串JSON格式
* @throws Exception 异常信息
*
* 使用示例
* Map<String, Object> data = new HashMap<>();
* Map<String, String> thing1 = new HashMap<>();
* thing1.put("value", "测试内容");
* data.put("thing1", thing1);
* String result = AppletControllerUtil.WXSendMsgUtil(openid, templateId, "pages/index/index", data);
*/
public static String WXSendMsgUtil(String touser, String templateId, String page, Map<String, Object> data) throws Exception {
// 1. 获取accessToken
String accessToken = com.ruoyi.system.ControllerUtil.WechatApiUtil.getAccessToken().get("access_token").toString();
// 2. 微信订阅消息接口地址
String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" + accessToken;
// 3. 组装请求参数
Map<String, Object> param = new HashMap<>();
param.put("touser", touser);
param.put("template_id", templateId);
if (page != null && !page.isEmpty()) {
param.put("page", page);
}
param.put("data", data);
String body = com.alibaba.fastjson2.JSON.toJSONString(param);
// 4. 发送POST请求
java.net.HttpURLConnection conn = (java.net.HttpURLConnection) new java.net.URL(url).openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
conn.setDoOutput(true);
try (java.io.OutputStream os = conn.getOutputStream()) {
os.write(body.getBytes(java.nio.charset.StandardCharsets.UTF_8));
}
// 5. 读取响应
java.io.InputStream is = conn.getInputStream();
StringBuilder sb = new StringBuilder();
byte[] buf = new byte[1024];
int len;
while ((len = is.read(buf)) != -1) {
sb.append(new String(buf, 0, len, java.nio.charset.StandardCharsets.UTF_8));
}
is.close();
return sb.toString();
}
//时间转化将int的时间戳转换为时间这个方法用于订单详情里面的预约时间
public static String timeStamp2Date(Order order) {
// 定义日期格式化模式
String formattedDate="";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");// 注意Java的Date构
if(order!=null){
if (order.getMakeTime() != null){
// 将时间戳转换为Date对象
Date date = new Date((long) order.getMakeTime() * 1000);
formattedDate = sdf.format(date);
if (order.getMakeHour() != null){
formattedDate += " " + order.getMakeHour();
}
}
}
return formattedDate.replace("-", "~");
}
}

View File

@ -0,0 +1,113 @@
package com.ruoyi.system.ControllerUtil;
import com.alibaba.fastjson2.JSONObject;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
/**
* 高德地图工具类
* 提供常用的地图相关功能如根据经纬度获取城市逆地理编码等
* 需要在高德开放平台注册并获取Web服务Key
*/
public class GaoDeMapUtil {
// 请替换为你自己的高德Web服务Key
private static final String GAODE_KEY = "YOUR_GAODE_WEB_KEY";
/**
* 根据经纬度获取所在城市名称
* @param longitude 经度
* @param latitude 纬度
* @return 城市名称"上海市"失败返回null
*/
public static String getCityByLocation(double longitude, double latitude) {
try {
String url = String.format(
"https://restapi.amap.com/v3/geocode/regeo?location=%f,%f&key=%s&extensions=base",
longitude, latitude, GAODE_KEY
);
HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
conn.setRequestMethod("GET");
conn.setDoInput(true);
InputStream is = conn.getInputStream();
StringBuilder sb = new StringBuilder();
byte[] buf = new byte[1024];
int len;
while ((len = is.read(buf)) != -1) {
sb.append(new String(buf, 0, len, StandardCharsets.UTF_8));
}
is.close();
JSONObject json = JSONObject.parseObject(sb.toString());
if (json.getIntValue("status") == 1) {
JSONObject regeocode = json.getJSONObject("regeocode");
if (regeocode != null) {
JSONObject addressComponent = regeocode.getJSONObject("addressComponent");
if (addressComponent != null) {
return addressComponent.getString("city");
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* 经纬度逆地理编码获取详细地址
* @param longitude 经度
* @param latitude 纬度
* @return 详细地址字符串失败返回null
*/
public static String getAddressByLocation(double longitude, double latitude) {
try {
String url = String.format(
"https://restapi.amap.com/v3/geocode/regeo?location=%f,%f&key=%s&extensions=base",
longitude, latitude, GAODE_KEY
);
HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
conn.setRequestMethod("GET");
conn.setDoInput(true);
InputStream is = conn.getInputStream();
StringBuilder sb = new StringBuilder();
byte[] buf = new byte[1024];
int len;
while ((len = is.read(buf)) != -1) {
sb.append(new String(buf, 0, len, StandardCharsets.UTF_8));
}
is.close();
JSONObject json = JSONObject.parseObject(sb.toString());
if (json.getIntValue("status") == 1) {
JSONObject regeocode = json.getJSONObject("regeocode");
if (regeocode != null) {
return regeocode.getString("formatted_address");
}
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* 计算两个经纬度点之间的直线距离单位
* @param lng1 第一个点经度
* @param lat1 第一个点纬度
* @param lng2 第二个点经度
* @param lat2 第二个点纬度
* @return 距离
*/
public static double getDistance(double lng1, double lat1, double lng2, double lat2) {
double radLat1 = Math.toRadians(lat1);
double radLat2 = Math.toRadians(lat2);
double a = radLat1 - radLat2;
double b = Math.toRadians(lng1) - Math.toRadians(lng2);
double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2)
+ Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
s = s * 6378137.0; // 地球半径
s = Math.round(s * 10000d) / 10000d;
return s;
}
}

View File

@ -5,11 +5,20 @@ import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.AppleDoMain.TemplateData;
import com.ruoyi.system.domain.AppleDoMain.WxMssVo;
import com.ruoyi.system.domain.Order;
import com.ruoyi.system.domain.ServiceGoods;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
/**
* 微信小程序通知消息推送工具类
@ -19,8 +28,12 @@ import com.alibaba.fastjson2.JSONObject;
public class WXsendMsgUtil {
// 微信小程序的AppID和AppSecret请替换为你自己的
private static final String APPID = "YOUR_APPID";
private static final String APPSECRET = "YOUR_APPSECRET";
private static final String APPID = "wx73d0202b3c8a6d68";
private static final String APPSECRET = "c0871da0ca140930420c695147f3694b";
private static final String PAY_SUCCESS="YKnuTCAD-oEEhNGoI3LUVkAqNsykOMTcyrf71S9vev8"; //下单成功通知
private static final String ORDER_STATUS="5lA-snytEPl25fBS7rf6rQi8Y0i5HOSdG0JMVdUnMcU"; // ##订单状态通知
private static final String PAY_GOODS="pv3cba-wPoinUbBZSskp0KpDNnJwrHqS0rvGBfDNQ1M"; //##商品支付通知
/**
* 获取微信小程序全局唯一后台接口调用凭据 access_token
@ -44,57 +57,117 @@ public class WXsendMsgUtil {
return json.getString("access_token");
}
/**
* 发送微信小程序订阅消息
* @param accessToken access_token
* @param touser 接收者openid
* @param templateId 模板ID
* @param page 跳转页面可选
* @param data 模板内容Map<String, Object>{"thing1":{"value":"内容"}}
* @return 微信接口响应
* @throws Exception 异常
*/
public static String sendSubscribeMsg(String accessToken, String touser, String templateId, String page, Map<String, Object> data) throws Exception {
String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" + accessToken;
Map<String, Object> param = new HashMap<>();
param.put("touser", touser);
param.put("template_id", templateId);
if (page != null && !page.isEmpty()) {
param.put("page", page);
}
param.put("data", data);
String body = JSON.toJSONString(param);
HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
conn.setDoOutput(true);
try (OutputStream os = conn.getOutputStream()) {
os.write(body.getBytes(StandardCharsets.UTF_8));
}
InputStream is = conn.getInputStream();
StringBuilder sb = new StringBuilder();
byte[] buf = new byte[1024];
int len;
while ((len = is.read(buf)) != -1) {
sb.append(new String(buf, 0, len, StandardCharsets.UTF_8));
}
is.close();
return sb.toString();
//公共推送
public static String PublicPush(WxMssVo wxMssVo) throws Exception {
RestTemplate restTemplate = new RestTemplate();
// String accessToken = getAccessToken();
//这里简单起见我们每次都获取最新的access_token
String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" + getAccessToken();
ResponseEntity<String> responseEntity =
restTemplate.postForEntity(url, wxMssVo, String.class);
return responseEntity.getBody();
}
/**
* 示例如何推送微信小程序订阅消息
*/
public static void main(String[] args) throws Exception {
// 1. 获取access_token
String accessToken = getAccessToken();
// 2. 组装消息内容
Map<String, Object> data = new HashMap<>();
Map<String, String> thing1 = new HashMap<>();
thing1.put("value", "测试内容");
data.put("thing1", thing1);
// 3. 发送消息
String result = sendSubscribeMsg(accessToken, "OPENID", "TEMPLATE_ID", "pages/index/index", data);
System.out.println("推送结果:" + result);
// /**
// * 发送微信小程序订阅消息
// * @param accessToken access_token
// * @param touser 接收者openid
// * @param templateId 模板ID
// * @param page 跳转页面可选
// * @param data 模板内容Map<String, Object>{"thing1":{"value":"内容"}}
// * @return 微信接口响应
// * @throws Exception 异常
// */
// public static String sendSubscribeMsg(String accessToken, String touser, String templateId, String page, Map<String, Object> data) throws Exception {
// System.out.println("0001access_token" + accessToken);
// String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" + accessToken;
// Map<String, Object> param = new HashMap<>();
// param.put("touser", touser);
// param.put("template_id", templateId);
// if (page != null && !page.isEmpty()) {
// param.put("page", page);
// }
// param.put("data", data);
// String body = JSON.toJSONString(param);
// HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
// conn.setRequestMethod("POST");
// conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
// conn.setDoOutput(true);
// try (OutputStream os = conn.getOutputStream()) {
// os.write(body.getBytes(StandardCharsets.UTF_8));
// }
// InputStream is = conn.getInputStream();
// StringBuilder sb = new StringBuilder();
// System.out.println("0001sb.toString()" + sb.toString());
// byte[] buf = new byte[1024];
// int len;
// while ((len = is.read(buf)) != -1) {
// sb.append(new String(buf, 0, len, StandardCharsets.UTF_8));
// }
// is.close();
// return sb.toString();
// }
//微信推送第一步通知用户预约成功
public static String sendMsgForUserInfo(String openid, Order order, ServiceGoods serviceGoods) throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//拼接推送的模版
WxMssVo wxMssVo = new WxMssVo();
wxMssVo.setTouser(openid);//用户的openid要发送给那个用户通常这里应该动态传进来的
wxMssVo.setTemplate_id(PAY_SUCCESS);//订阅消息模板id
wxMssVo.setPage("/pages/mine/serveOrder/index");
String mark = order.getMark();
if (StringUtils.isEmpty( mark)){
mark="暂无备注";
}
Map<String, TemplateData> m = new HashMap<>(3);
m.put("thing44", new TemplateData(serviceGoods.getTitle()));
m.put("character_string22", new TemplateData(order.getOrderId()));
m.put("time1", new TemplateData(AppletControllerUtil.timeStamp2Date(order)));
m.put("thing27", new TemplateData(mark));
m.put("time10", new TemplateData(sdf.format(new Date())));
System.out.println("thing44"+ serviceGoods.getTitle());
System.out.println("character_string22"+ order.getOrderId());
System.out.println("time1"+ AppletControllerUtil.timeStamp2Date(order));
System.out.println("thing27"+ order.getMark());
System.out.println("time10"+sdf.format(new Date()));
System.out.println("0002订单号" + m.toString());
wxMssVo.setData(m);
return PublicPush(wxMssVo);
}
//微信推送第er步给师傅通知派单情况
public static String sendMsgForWorkerInfo(String openid, Order order, ServiceGoods serviceGoods) throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//拼接推送的模版
WxMssVo wxMssVo = new WxMssVo();
wxMssVo.setTouser(openid);//用户的openid要发送给那个用户通常这里应该动态传进来的
wxMssVo.setTemplate_id(ORDER_STATUS);//订阅消息模板id
wxMssVo.setPage("/pages/tab/serve/index");
String mark = order.getMark();
if (StringUtils.isEmpty( mark)){
mark="暂无备注";
}
Map<String, TemplateData> m = new HashMap<>(3);
m.put("thing15", new TemplateData(serviceGoods.getTitle()));
m.put("character_string5", new TemplateData(order.getOrderId()));
m.put("date3", new TemplateData(AppletControllerUtil.timeStamp2Date(order)));
m.put("thing1", new TemplateData(order.getAddress()));
m.put("thing9", new TemplateData(sdf.format(new Date())));
System.out.println("0002订单号" + m.toString());
wxMssVo.setData(m);
return PublicPush(wxMssVo);
}
}

View File

@ -82,6 +82,8 @@ public class WechatPayUtil {
*/
private static final RestTemplate restTemplate = new RestTemplate();
/**
* 小程序统一下单JSAPI
* @param openid 用户openid
@ -92,7 +94,7 @@ public class WechatPayUtil {
* @param attach 附加数据可选
* @return 统一下单结果包含小程序端调起支付的参数
*/
public Map<String, Object> unifiedOrder(String openid, String orderNo, int totalFee, String body, String notifyUrl, String attach) {
public Map<String, Object> unifiedOrder(String openid, String orderNo, int totalFee, String body, String notifyUrl, String attach) {
Map<String, Object> result = new HashMap<>();
try {
// 1. 参数校验

View File

@ -0,0 +1,19 @@
package com.ruoyi.system.domain.AppleDoMain;
public class TemplateData {
private String value;//
public TemplateData(String value) {
this.value = value;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}

View File

@ -0,0 +1,42 @@
package com.ruoyi.system.domain.AppleDoMain;
import java.util.Map;
public class WxMssVo {
private String touser;//用户openid
private String template_id;//订阅消息模版id
private String page = "pages/index/index";//默认跳到小程序首页
private Map<String, TemplateData> data;//推送文字
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 getPage() {
return page;
}
public void setPage(String page) {
this.page = page;
}
public Map<String, TemplateData> getData() {
return data;
}
public void setData(Map<String, TemplateData> data) {
this.data = data;
}
}