- 生成运单 接口生成云单后无法在快递管家中查询到?
我使用 生成运单接口生成运单后 https://api.weixin.qq.com/cgi-bin/express/business/order/add?access_token=ACCESS_TOKEN 1: 该运单无法在快递管家中查询到 https://vip.zto.com/login 73588021027366 [图片] 2:我找到我们签约的中通快递员,说明运单号,他们的系统可以查询到 [图片] 3:但是无法在无法在快递管家中查询到 https://vip.zto.com/login [图片][图片][图片][图片] 4:网点面单也确认了是同一个 分别是 java中的配置,快递员查询到的信息,快递管家中的面单信息,小程序物流助手配置 [图片] [图片] [图片] [图片] 所以这到底是为什么? ```java @PostMapping("/create-order/{orderId}") public ReturnBean> createLogisticsOrder( @PathVariable("orderId") Long orderId, @RequestBody(required = false) Map shopData) { log.info("创建物流订单请求,orderId={}", orderId); // 步骤1:验证订单状态 AccountsOrderEntity order = accountsOrderService.getById(orderId); if (order == null) { throw SystemException.error(ErrorCodeEnum.DATA_NOT_FOUND, "订单不存在"); } if (!"pending_shipment".equals(order.getStatus())) { throw SystemException.error(ErrorCodeEnum.OPERATION_FAILED, "只有待发货的订单才能创建物流订单,当前状态: " + order.getStatus()); } // 步骤2:检查是否已有物流订单 LambdaQueryWrapper logisticsWrapper = new LambdaQueryWrapper<>(); logisticsWrapper.eq(LogisticsOrderEntity::getOrderId, orderId); LogisticsOrderEntity existingLogisticsOrder = logisticsOrderService.getOne(logisticsWrapper); if (existingLogisticsOrder != null) { // 如果运单已取消,清除Redis缓存并允许重新创建 if ("cancelled".equals(existingLogisticsOrder.getStatus())) { log.warn("订单已存在但运单已取消,清除缓存并允许重新创建,orderId={}, waybillId={}", orderId, existingLogisticsOrder.getWaybillId()); String cacheKey = LOGISTICS_REDIS_ADD_ORDER + orderId; try { RedisUtil.delete(cacheKey); log.info("已清除已取消运单的Redis缓存,orderId={}", orderId); } catch (Exception e) { log.warn("清除Redis缓存失败,但不影响业务,orderId={}, error={}", orderId, e.getMessage()); } // 继续执行,允许重新创建物流订单 } else { // 运单未取消,返回现有运单信息 log.info("订单已存在物流订单,orderId={}, waybillId={}", orderId, existingLogisticsOrder.getWaybillId()); Map result = new HashMap<>(); result.put("waybill_id", existingLogisticsOrder.getWaybillId()); result.put("company_name", existingLogisticsOrder.getCompanyName()); result.put("status", existingLogisticsOrder.getStatus()); result.put("is_existing", true); return ReturnBean.success("该订单已存在物流订单", result); } } // 步骤3:验证收货信息 List missingFields = new ArrayList<>(); if (StringUtils.isBlank(order.getShippingName())) { missingFields.add("收货人姓名"); } if (StringUtils.isBlank(order.getShippingPhone())) { missingFields.add("收货人电话"); } if (StringUtils.isBlank(order.getShippingAddress())) { missingFields.add("收货地址"); } if (!missingFields.isEmpty()) { throw SystemException.error(ErrorCodeEnum.PARAM_NOT_NULL, "订单缺少以下信息:" + String.join("、", missingFields)); } // 步骤4:获取用户OpenID String openid = getUserOpenid(order); if (StringUtils.isBlank(openid)) { throw SystemException.error(ErrorCodeEnum.DATA_NOT_FOUND, "无法获取用户OpenID,请确保订单已支付"); } // 步骤5:查询订单商品项 LambdaQueryWrapper itemWrapper = new LambdaQueryWrapper<>(); itemWrapper.eq(AccountsOrderitemEntity::getOrderId, orderId); List orderItems = accountsOrderitemService.list(itemWrapper); if (orderItems == null || orderItems.isEmpty()) { throw SystemException.error(ErrorCodeEnum.DATA_NOT_FOUND, "订单商品项为空"); } // 步骤6:构建物流订单数据 Map logisticsData = buildLogisticsOrderData(order, orderItems, openid, shopData); // 步骤7:检查Redis缓存,处理可能的异常情况(微信已创建但数据库未保存) String cacheKey = LOGISTICS_REDIS_ADD_ORDER + orderId; String cachedResult = RedisUtil.get(cacheKey); Map createResult; boolean isFromCache = false; if (StringUtils.isNotBlank(cachedResult)) { // Redis中有缓存,说明之前可能调用过微信API但数据库保存失败 log.warn("检测到Redis缓存,orderId={},可能之前创建过但数据库保存失败,尝试恢复", orderId); try { @SuppressWarnings("unchecked") Map parsedResult = JSON.parseObject(cachedResult, Map.class); // 检查缓存中的运单号是否已在数据库中存在 String cachedWaybillId = (String) parsedResult.get("waybill_id"); if (StringUtils.isNotBlank(cachedWaybillId)) { LambdaQueryWrapper waybillWrapper = new LambdaQueryWrapper<>(); waybillWrapper.eq(LogisticsOrderEntity::getWaybillId, cachedWaybillId); LogisticsOrderEntity existingByWaybill = logisticsOrderService.getOne(waybillWrapper); if (existingByWaybill != null) { // 检查运单状态:如果已取消,清除缓存并重新创建 if ("cancelled".equals(existingByWaybill.getStatus())) { log.warn("检测到缓存中的运单已取消,清除缓存并重新创建,orderId={}, waybillId={}", orderId, cachedWaybillId); RedisUtil.delete(cacheKey); // 继续执行,重新创建物流订单 createResult = weChatLogisticsService.createOrder(logisticsData); } else { // 数据库已存在该运单号且未取消,说明数据已恢复,直接返回 log.info("数据库已存在该运单号,数据已恢复,orderId={}, waybillId={}", orderId, cachedWaybillId); Map result = new HashMap<>(); result.put("waybill_id", existingByWaybill.getWaybillId()); result.put("company_name", existingByWaybill.getCompanyName()); result.put("status", existingByWaybill.getStatus()); result.put("is_existing", true); result.put("is_recovered", true); return ReturnBean.success("该订单已存在物流订单(已恢复)", result); } } else { // 数据库不存在,但缓存中有数据,可能是之前创建失败,使用缓存继续处理 createResult = parsedResult; isFromCache = true; log.info("使用Redis缓存数据继续处理,orderId={}, waybillId={}", orderId, cachedWaybillId); } } else { // 缓存中没有运单号,删除无效缓存并重新创建 log.warn("Redis缓存中没有运单号,删除无效缓存并重新创建,orderId={}", orderId); RedisUtil.delete(cacheKey); createResult = weChatLogisticsService.createOrder(logisticsData); } } catch (Exception e) { // 缓存数据解析失败,说明缓存可能损坏,删除缓存并重新创建 log.error("解析Redis缓存数据失败,删除损坏的缓存并重新创建,orderId={}, error={}", orderId, e.getMessage(), e); RedisUtil.delete(cacheKey); createResult = weChatLogisticsService.createOrder(logisticsData); } } else { // Redis中没有缓存,说明是正常的新订单,可以安全创建 log.info("Redis无缓存,正常创建物流订单,orderId={}", orderId); createResult = weChatLogisticsService.createOrder(logisticsData); } // 步骤8:如果调用微信API成功,立即保存到Redis(4天过期,预留bug修复时间) if (Boolean.TRUE.equals(createResult.get("success"))) { try { String resultJson = JSON.toJSONString(createResult); RedisUtil.saveString(cacheKey, resultJson, LOGISTICS_CACHE_EXPIRE_TIME_BUG_FIX); log.info("微信API调用成功,结果已保存到Redis缓存(4天),orderId={}, waybillId={}", orderId, createResult.get("waybill_id")); } catch (Exception e) { log.warn("保存物流订单创建结果到Redis失败,但不影响业务,orderId={}, error={}", orderId, e.getMessage()); } } else { // API调用失败,抛出异常 throw SystemException.error(ErrorCodeEnum.OPERATION_FAILED, "创建物流订单失败: " + createResult.get("error")); } // 步骤9:保存物流订单到数据库 String waybillId = (String) createResult.get("waybill_id"); String companyCode = (String) createResult.get("company_code"); String companyName = (String) createResult.get("company_name"); LogisticsOrderEntity logisticsOrder = new LogisticsOrderEntity(); logisticsOrder.setOrderId(orderId); logisticsOrder.setWaybillId(waybillId); logisticsOrder.setCompanyCode(companyCode); logisticsOrder.setCompanyName(companyName); logisticsOrder.setStatus("created"); logisticsOrder.setWaybillData(JSON.toJSONString(createResult)); logisticsOrder.setCreatedAt(LocalDateTime.now()); // 设置物流费用字段(数据库字段不允许为NULL,必须设置默认值) logisticsOrder.setLogisticsFee(BigDecimal.ZERO); // 实际费用,创建时默认为0 logisticsOrder.setEstimatedFee(BigDecimal.ZERO); // 预估费用,创建时默认为0 // 设置错误信息字段(数据库字段不允许为NULL,必须设置默认值) logisticsOrder.setErrorMessage(""); // 错误信息,创建时默认为空字符串 try { logisticsOrderService.save(logisticsOrder); } catch (Exception e) { // 数据库保存失败,但微信已创建,Redis中已有4天缓存,可以后续恢复 log.error("数据库保存失败,但微信已创建订单,Redis缓存保留4天用于恢复,orderId={}, waybillId={}, error={}", orderId, waybillId, e.getMessage(), e); throw SystemException.error(ErrorCodeEnum.OPERATION_FAILED, "物流订单在微信中已创建,但数据库保存失败,请稍后重试或联系管理员恢复。运单号: " + waybillId); } // 步骤10:更新订单状态和物流信息 order.setLogisticsCompany(companyName); order.setLogisticsNumber(waybillId); order.setLogisticsStatus("created"); order.setStatus("shipped"); order.setShippedAt(LocalDateTime.now()); order.setUpdatedAt(LocalDateTime.now()); try { accountsOrderService.updateById(order); } catch (Exception e) { // 订单更新失败,但物流订单已保存,记录警告 log.warn("订单状态更新失败,但物流订单已保存,orderId={}, waybillId={}, error={}", orderId, waybillId, e.getMessage()); } // 步骤11:数据库保存成功,将Redis缓存过期时间改为30分钟(或删除) try { // 方案1:缩短过期时间为30分钟(推荐,保留短期缓存提升性能) String resultJson = JSON.toJSONString(createResult); RedisUtil.saveString(cacheKey, resultJson, LOGISTICS_CACHE_EXPIRE_TIME_NORMAL); log.info("数据库保存成功,Redis缓存过期时间已更新为30分钟,orderId={}, waybillId={}", orderId, waybillId); } catch (Exception e) { log.warn("更新Redis缓存过期时间失败,但不影响业务,orderId={}, error={}", orderId, e.getMessage()); } log.info("物流订单创建成功,orderId={}, waybillId={}, isFromCache={}", orderId, waybillId, isFromCache); Map result = new HashMap<>(); result.put("logistics_order_id", logisticsOrder.getId()); result.put("waybill_id", waybillId); result.put("company_name", companyName); result.put("status", "created"); return ReturnBean.success("物流订单创建成功", result); } ``` --- ## 调用的私有方法 ### 2. getUserOpenid - 获取用户OpenID **位置**: `org.example.huolingjava.logistics.controller.LogisticsController` ```java /** * 获取用户OpenID * 优先从payment_transactions表获取,其次从订单表获取 */ private String getUserOpenid(AccountsOrderEntity order) { // 1. 优先从payment_transactions表获取(微信官方数据) if (order.getPaymentOrderId() != null) { PaymentOrdersEntity paymentOrder = paymentOrdersService.getById(order.getPaymentOrderId()); if (paymentOrder != null && StringUtils.isNotBlank(paymentOrder.getOpenid())) { return paymentOrder.getOpenid(); } } // 2. 从payment_transactions表查询(根据订单号) if (StringUtils.isNotBlank(order.getOrderNumber())) { LambdaQueryWrapper transactionWrapper = new LambdaQueryWrapper<>(); transactionWrapper.like(PaymentTransactionsEntity::getOutTradeNo, order.getOrderNumber()) .orderByDesc(PaymentTransactionsEntity::getCreatedTime) .last("LIMIT 1"); PaymentTransactionsEntity transaction = paymentTransactionsService.getOne(transactionWrapper); if (transaction != null && StringUtils.isNotBlank(transaction.getOpenid())) { return transaction.getOpenid(); } } // 3. 使用订单保存的信息 if (StringUtils.isNotBlank(order.getOrderOpenid())) { return order.getOrderOpenid(); } if (StringUtils.isNotBlank(order.getPaymentOpenid())) { return order.getPaymentOpenid(); } return null; } ``` ### 3. buildLogisticsOrderData - 构建物流订单数据 **位置**: `org.example.huolingjava.logistics.controller.LogisticsController` ```java /** * 构建物流订单数据 */ private Map buildLogisticsOrderData( AccountsOrderEntity order, List orderItems, String openid, Map shopData) { Map logisticsData = new HashMap<>(); logisticsData.put("orderId", order.getId()); logisticsData.put("orderNumber", order.getOrderNumber()); logisticsData.put("customerName", order.getShippingName()); logisticsData.put("customerPhone", order.getShippingPhone()); logisticsData.put("customerAddress", order.getShippingAddress()); logisticsData.put("openid", openid); logisticsData.put("totalAmount", order.getActualAmount()); // 构建商品列表 List> products = new ArrayList<>(); for (AccountsOrderitemEntity item : orderItems) { Map product = new HashMap<>(); product.put("id", item.getProductId()); product.put("name", item.getProductName()); product.put("quantity", item.getQuantity()); product.put("category", item.getProductCategory()); products.add(product); } logisticsData.put("products", products); // 计算总重量(简化处理,默认0.1kg) logisticsData.put("totalWeight", 0.1); // 店铺信息(如果有) if (shopData != null) { logisticsData.put("shop", shopData); } return logisticsData; } ``` --- ## 调用的Service方法 ### 4. WeChatLogisticsService.createOrder - 创建物流订单(微信API) **位置**: `org.example.huolingjava.logistics.service.WeChatLogisticsService` ```java /** * 创建物流订单 * * @param orderData 订单数据,包含: * - orderId: 订单ID * - orderNumber: 订单号 * - customerName: 收货人姓名 * - customerPhone: 收货人电话 * - customerAddress: 收货地址 * - openid: 用户微信OpenID * - products: 商品列表 * - totalWeight: 总重量(kg) * - totalAmount: 订单总金额(元) * @return 创建结果,包含waybill_id、company_code、company_name等 */ public Map createOrder(Map orderData) { if (orderData == null) { throw SystemException.error(ErrorCodeEnum.PARAM_NOT_NULL, "订单数据不能为空"); } // 获取access_token String accessToken = getAccessToken(); // 构建请求数据 Map requestData = buildCreateOrderRequest(orderData); // 调用微信API(使用官方新接口路径) // 官方文档:https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/express/express-by-business/addOrder.html String url = properties.getBaseUrl() + "/order/add"; url += "?access_token=" + accessToken; try { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); headers.set("User-Agent", "HuolingMP/1.0"); HttpEntity requestEntity = new HttpEntity<>( JSON.toJSONString(requestData), headers); ResponseEntity response = restTemplate.postForEntity( url, requestEntity, String.class); JSONObject result = JSON.parseObject(response.getBody()); if (result.getIntValue("errcode") == 0) { String waybillId = result.getString("waybill_id"); String orderId = result.getString("order_id"); log.info("创建物流订单成功,waybillId={}, orderId={}", waybillId, orderId); Map responseData = new HashMap<>(); responseData.put("success", true); responseData.put("waybill_id", waybillId); responseData.put("company_code", properties.getZtoCompanyCode()); responseData.put("company_name", properties.getZtoCompanyName()); responseData.put("order_id", orderId); return responseData; } else { int errcode = result.getIntValue("errcode"); String errmsg = result.getString("errmsg"); log.error("创建物流订单失败,errcode={}, errmsg={}", errcode, errmsg); // 处理特殊错误码 if (errcode == 40066) { throw SystemException.error(ErrorCodeEnum.OPERATION_FAILED, "物流订单创建失败:回调URL未在微信后台配置。回调URL: " + properties.getCallbackUrl()); } throw SystemException.error(ErrorCodeEnum.OPERATION_FAILED, "创建物流订单失败: " + errmsg); } } catch (SystemException e) { throw e; } catch (Exception e) { log.error("创建物流订单异常", e); throw SystemException.error(ErrorCodeEnum.OPERATION_FAILED, "创建物流订单异常: " + e.getMessage()); } } ``` ### 5. WeChatLogisticsService.getAccessToken - 获取微信access_token **位置**: `org.example.huolingjava.logistics.service.WeChatLogisticsService` ```java /** * 获取微信access_token * * @return access_token字符串 */ public String getAccessToken() { String url = "https://api.weixin.qq.com/cgi-bin/token"; Map params = new HashMap<>(); params.put("grant_type", "client_credential"); params.put("appid", properties.getAppId()); params.put("secret", properties.getAppSecret()); try { StringBuilder urlBuilder = new StringBuilder(url); urlBuilder.append("?grant_type=client_credential"); urlBuilder.append("&appid=").append(properties.getAppId()); urlBuilder.append("&secret=").append(properties.getAppSecret()); ResponseEntity response = restTemplate.getForEntity(urlBuilder.toString(), String.class); JSONObject result = JSON.parseObject(response.getBody()); if (result.containsKey("access_token")) { String accessToken = result.getString("access_token"); log.info("获取微信access_token成功"); return accessToken; } else { String errmsg = result.getString("errmsg"); int errcode = result.getIntValue("errcode"); log.error("获取微信access_token失败,errcode={}, errmsg={}", errcode, errmsg); throw SystemException.error(ErrorCodeEnum.OPERATION_FAILED, "获取微信access_token失败: " + errmsg); } } catch (Exception e) { log.error("获取微信access_token异常", e); throw SystemException.error(ErrorCodeEnum.OPERATION_FAILED, "获取微信access_token异常: " + e.getMessage()); } } ``` ### 6. WeChatLogisticsService.buildCreateOrderRequest - 构建创建物流订单的请求数据 **位置**: `org.example.huolingjava.logistics.service.WeChatLogisticsService` ```java /** * 构建创建物流订单的请求数据 */ @SuppressWarnings("unchecked") private Map buildCreateOrderRequest(Map orderData) { Map requestData = new HashMap<>(); // 基础信息 requestData.put("add_source", 2); // 2表示小程序 requestData.put("order_id", String.valueOf(orderData.get("orderNumber"))); requestData.put("delivery_id", properties.getZtoDeliveryId()); requestData.put("biz_id", properties.getZtoBizId()); requestData.put("openid", String.valueOf(orderData.get("openid"))); requestData.put("wx_appid", properties.getAppId()); requestData.put("notify_url", properties.getCallbackUrl()); // 发货人信息 WeChatLogisticsProperties.SenderInfo sender = properties.getSender(); Map senderMap = new HashMap<>(); senderMap.put("name", sender.getName()); senderMap.put("tel", sender.getTel()); senderMap.put("mobile", sender.getMobile()); senderMap.put("company", sender.getCompany()); senderMap.put("province", sender.getProvince()); senderMap.put("city", sender.getCity()); senderMap.put("area", sender.getArea()); senderMap.put("address", sender.getAddress()); requestData.put("sender", senderMap); // 收货人信息 Map receiverMap = new HashMap<>(); String customerName = String.valueOf(orderData.get("customerName")); String customerPhone = String.valueOf(orderData.get("customerPhone")); String customerAddress = String.valueOf(orderData.get("customerAddress")); receiverMap.put("name", customerName.length() > 20 ? customerName.substring(0, 20) : customerName); receiverMap.put("tel", customerPhone); receiverMap.put("mobile", customerPhone); // 解析地址(简化处理,实际应该解析省市区) receiverMap.put("province", "广东省"); receiverMap.put("city", "中山市"); receiverMap.put("area", "中山港街道"); receiverMap.put("address", customerAddress.length() > 50 ? customerAddress.substring(0, 50) : customerAddress); requestData.put("receiver", receiverMap); // 货物信息 Map cargoMap = new HashMap<>(); java.util.List> products = (java.util.List>) orderData.get("products"); if (products == null || products.isEmpty()) { throw SystemException.error(ErrorCodeEnum.PARAM_NOT_NULL, "商品列表不能为空"); } cargoMap.put("count", products.size()); // 计算总重量 Double totalWeight = orderData.get("totalWeight") != null ? Double.parseDouble(String.valueOf(orderData.get("totalWeight"))) : 0.1; if (totalWeight <= 0) { totalWeight = 0.1; // 默认0.1kg } cargoMap.put("weight", totalWeight); // 商品详情列表 java.util.List> detailList = new java.util.ArrayList<>(); for (Map product : products) { Map detail = new HashMap<>(); String productName = String.valueOf(product.get("name")); // 移除括号,限制长度 productName = productName.replace("(", "").replace(")", ""); detail.put("name", productName.length() > 30 ? productName.substring(0, 30) : productName); detail.put("count", product.get("quantity")); detailList.add(detail); } cargoMap.put("detail_list", detailList); requestData.put("cargo", cargoMap); // 店铺信息(使用第一个商品) Map shopMap = new HashMap<>(); Map firstProduct = products.get(0); String goodsName = String.valueOf(firstProduct.get("name")); goodsName = goodsName.replace("(", "").replace(")", ""); shopMap.put("goods_name", goodsName.length() > 30 ? goodsName.substring(0, 30) : goodsName); shopMap.put("goods_count", products.size()); requestData.put("shop", shopMap); return requestData; }
2025-12-26 - 微信开发者工具有时不显示登录的按钮
[图片]
2025-11-17 - 苹果手机再使用蓝牙的onBLECharacteristicValueChange时会重复的接收消息?
小程序逻辑: 在小程序的逻辑中,我们在首页的 onShow 方法中调用封装在 blueUtil.js 中的 onBLECharacteristicValueChange 来开启蓝牙特征值变化的监听。在首页,通过扫码获取蓝牙设备的名称后,成功连接到蓝牙设备。这时,我们可以发送命令并接收消息。 从首页可以跳转到一个名为 "bed" 的页面。在该页面的 onLoad 中,我们再次调用封装在 blueUtil.js 中的 onBLECharacteristicValueChange 来进行消息监听。此时,发送和接收蓝牙消息的功能正常,且不会出现重复接收的情况,确保只有 "bed" 页面处理接收到的消息。然而,当用户从 "bed" 页面返回到首页时,Bed会接收到一次蓝牙消息,这条消息是上次接收到的内容。 bed页面发送和接受消息。正常且不重复 [图片] 返回首页时只有一个接受消息的动作且消息是上次的 [图片]
2025-07-17 - 省市区选择器《picker》 在PC端中的微信启动的小程序中无法调用?
这是正常的 [图片][图片] 不正常的是 点击无效果 [图片] <picker slot="extra" level="sub-district" class="feed-picker" disabled="{{m_bReadOnly}}" mode="region" bindchange="onRegionChange" value="{{ m_arrRegion }}"> <view style="color:#333;">{{m_agentArea}}</view> </picker> onRegionChange: function(event) { if (this.data.m_bReadOnly) { Notify('已通过审核,不能修改!'); return; } var arrRegion = event.detail.value; var strRegion = arrRegion.join('/'); this.setData({m_arrRegion: arrRegion, m_agentArea: strRegion}); },
2025-01-06 - 我将代码提交到体验版后,新功能不开启调试模式就无效果?
我新加了一个功能在本地已走通,然后提交到体验版进行测试。发现无效果,之后我打开调试模式想看看数据值的走向,结果发现只要打开调试模式就功能正常,关闭就不正常。来回关闭打开了好几次后关闭调试模式也功能正常了。但是用其他微信账号来使用时又出现了这个问题? 自助五行哪里的图片路径和描述都是从后台获取的一个集合中的数据 如果这个页面有图片和描述展示就必然有数据这个数据是保存在 app.js文件中的。 [图片] 新功能是 启动一台设备会根据他的五行属性播放相应的音乐,如果没有就播放默认音乐。 播放音乐的指令代码片段,新功能就是在原先的一个方法中插入这个方法的调用,根据逻辑修改命令。 settleProjectCmd(){ let curProject = this.data.m_curProject; let projectCmd = curProject.project_cmd; let bIsBest = this.data.m_bIsBest; // 如果是AI理疗就进入五行音乐的逻辑 if(bIsBest > 0){ let userInfo = this.data.m_userInfo; let wuXing = this.data.m_wuXing; // 如果用户有旺盛的五行体制就是使用 克制的音乐来播放 if(userInfo.user_wu_xing_ai != null && userInfo.user_wu_xing_ai != undefined && userInfo.user_wu_xing_ai != '' ){ return projectCmd+wuXing[userInfo.user_wu_xing_ai].restrain_music; }else{ // 如果用户没有体制或特殊的模式就使用基础的音乐 return projectCmd+DEFAULT_MUSIC; } } // 如果启动的模式是 (720睡眠/亚健康 )或者 (360睡眠/360睡眠/舒缓压力) 就拼接011音乐 if(projectCmd === CMD_START_720 || projectCmd === CMD_START_360 ){ return projectCmd+DEFAULT_MUSIC_SLEEP; } // 如果用户没有体制或特殊的模式就使用基础的音乐 return projectCmd+DEFAULT_MUSIC; }, [图片][图片] 所以我不明白的是为什么 打开调试模式就功能正常(我开调试模式就是想看错误在哪,结果调试就是正常的不开就是无效果的)
2024-07-16 - 没有使用setData()就将page里的data数据更改了?
doTapWuXingCheck(event) { const { id: strCodeID } = event.currentTarget.dataset; let strCodeIDArr = strCodeID.split('-'); let wuXingGPT = this.data.m_wuXingGPT; let wuXingRadio = this.data.m_wuXingRadio; // 修改选择状态,直接取反原先的值 wuXingGPT[strCodeIDArr[0]][strCodeIDArr[1]].on = !wuXingGPT[strCodeIDArr[0]][strCodeIDArr[1]].on; let sum = 0; wuXingGPT.map((items,index) => { // 判断某个五行中是否有选择如果有选择就进行修改单选的图片展示 const result = items.find(item => item.on); if(result != undefined && result != null && result != ''){ wuXingRadio[index].flag = true; }else{ wuXingRadio[index].flag = false; } // 使用reduce函数统计集合中age参数的值总和 const wuXingSum = items.reduce((accumulator, currentValue) => accumulator + currentValue.on, 0); wuXingRadio[index].sum = wuXingSum; sum += wuXingSum; }) console.log("wuXingRadio: ",this.data.m_wuXingRadio); console.log("m_wuXingGPT: ",this.data.m_wuXingGPT); if(sum > 3){ Notify('您已选择超过3项!'); return; } this.setData({ m_wuXingGPT: wuXingGPT, m_wuXingRadio: wuXingRadio }) }, 我记得以前正常的逻辑是:如果大于3这个方法就直接退出,没有调用到setData()方法来修改参数所以 page里的data数据是不会进行更改的。现在却更改了 [图片]
2024-07-09 - <web-view>组件无法进入1688阿里巴巴网站?
我公司在1688上有个商店,现在做了一个小程序希望有个按钮可以跳转到1688的商店。我使用<web-view>来实现跳转,发现商店是准确跳转到了但是一秒不到就之间报错说网址访问不到。 [图片][图片][图片] 我尝试过这几个1688网址来进入都不可以: 1,https://m.1688.com/ 2,https://shop1962p79790768.1688.com/ 3,https://www.1688.com/
2024-06-04 - <web-view>组件无法进入https://qr.1688.com?
我公司在阿里的1688上开了一个店,现在在小程序上添加一个按钮可跳转到1688的移动端网址。但是进去后先展示出了网页过后一秒就报无法访问此网站。 [图片][图片][图片] <web-view src="https://qr.1688.com/s/fcmOt1iy" bindmessage="onWebMessage" bindload="onWebLoad" /> 阿里1688错误网址: 1: https://m.1688.com/?__removesafearea__=1&cbu_sv_id=6174a6e2-9c2c-4fa1-8f1a-df55539ab19e&src_cna=M1jkHrYWvgkCAbfvQyMMwK78&visitorId=6174a6e2-9c2c-4fa1-8f1a-df55539ab19e 2: https://shop1962p79790768.1688.com/page/index.html?spm=0.0.wp_pc_common_header_companyName_undefined.0[图片]
2024-06-03 - 被动回复消息无反应?
服务器(Controller)代码 @RequestMapping(value = "getToken") @GetMapping(produces = "text/plain;charset=utf-8") @ResponseBody public void getToken(HttpServletRequest request, HttpServletResponse response) { if (StringUtils.isBlank(request.getParameter("signature"))) { return; } String msgSignature = request.getParameter("msg_signature"); String signature = request.getParameter("signature"); String timestamp = request.getParameter("timestamp"); String nonce = request.getParameter("nonce"); String echostr = request.getParameter("echostr"); try { if (!wxMpService.checkSignature(timestamp, nonce, signature)) { // 消息签名不正确,说明不是公众平台发过来的消息 response.getWriter().println("非法请求"); return; } if (StringUtils.isNotBlank(echostr)) { // 说明是一个仅仅用来验证的请求,回显echostr response.getWriter().println(Long.valueOf(echostr)); return; } String encryptType = StringUtils.isBlank(request.getParameter("encrypt_type")) ? "raw" : request.getParameter("encrypt_type"); WxMpXmlMessage inMessage = null; if ("raw".equals(encryptType)) { // 明文传输的消息 inMessage = WxMpXmlMessage.fromXml(request.getInputStream()); } else if ("aes".equals(encryptType)) { // 是aes加密的消息 inMessage = WxMpXmlMessage.fromEncryptedXml(request.getInputStream(), weixinService.getWxMpService().getWxMpConfigStorage(), timestamp, nonce, msgSignature); } else { response.getWriter().println("不可识别的加密类型"); return; } log.debug("__获取到的消息__"+inMessage.toString()); String event = inMessage.getEvent(); // 判定是关注公众号操作还是 对公众进行发送消息 if(StringUtils.isNotBlank(event)){ // 这个是关注与取消关注的逻辑操作 this.attentionGzh(inMessage,event); }else { // 回复消息 gzhUserService.passiveReplyMessage(inMessage, response); } inMessage.getEvent(); } catch (Exception e) { e.printStackTrace(); } } // 回复消息 service public String passiveReplyMessage(WxMpXmlMessage inMessage, HttpServletResponse response){ String msgType = inMessage.getMsgType(); if (msgType.equals("text")){ String content = inMessage.getContent(); String xmlTextString = ""; if (content.equals("绑定账号")){ xmlTextString = xmlText(inMessage.getToUser(), inMessage.getFromUser(), "好的"); } if (content.equals("1")){ xmlTextString = xmlText(inMessage.getToUser(), inMessage.getFromUser(), "好的"); } // 回复消息 if (StringUtils.isNotBlank(xmlTextString)){ try { response.setCharacterEncoding("UTF-8"); response.getWriter().println(xmlTextString); }catch (IOException e){ throw new IORuntimeException(e); } } return xmlTextString; } return ""; } 接受数据 xlm已转对象 {"allFieldsMap":{"Content":"1","CreateTime":"1695626434","ToUserName":"gh_","FromUserName":"olB_","MsgType":"text","MsgId":"24275533520139327"},"toUser":"gh_","fromUser":"olB_","createTime":1695626434,"msgType":"text","content":"1","msgId":242,"scanCodeInfo":{},"sendPicsInfo":{"picList":[]},"sendLocationInfo":{},"hardWare":{}} 返回的XML (我服务器的xml名称) xmlTextString <xml><ToUserName><![CDATA[gh_]]></ToUserName><FromUserName><![CDATA[olB_]]></FromUserName><CreateTime>1695626435704</CreateTime><MsgType><![CDATA[text]]></MsgType><Content><![CDATA[好的]]></Content></xml> [图片]
2023-09-25 - 支付回调,wxPayService.parseOrderNotifyV3Result一直报null?
jar包 com.github.binarywang weixin-java-pay 4.5.3.B 观看的接口文档 支付通知APIhttps://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_5.shtml JAVA代码 service层 注:数据都已经接受到了 PayNotifyForm 是通知接口传过来的参数 public void payNotify(String appid, PayNotifyForm payNotifyForm, HttpServletResponse response, HttpServletRequest request) throws Exception { // 自己写的创建WxPayService 对象方法 将 密钥证书等等输入 WxPayService wxPayService = this.getWxPayService(appid); SignatureHeader signatureHeader = new SignatureHeader(); signatureHeader.setTimeStamp(response.getHeader("Wechatpay-Timestamp")); signatureHeader.setNonce(response.getHeader("Wechatpay-Nonce")); signatureHeader.setSerial(response.getHeader("Wechatpay-Serial")); signatureHeader.setSignature(response.getHeader("Wechatpay-Signature")); // 这段代码一开始没有加,现在加了还是在报错 SignatureHeader.SignatureHeaderBuilder builder = signatureHeader.builder(); builder.timeStamp(response.getHeader("Wechatpay-Timestamp")); builder.nonce(response.getHeader("Wechatpay-Nonce")); builder.serial(response.getHeader("Wechatpay-Serial")); builder.signature(response.getHeader("Wechatpay-Signature")); WxPayNotifyV3Result notifyV3Result = wxPayService.parseOrderNotifyV3Result(payNotifyForm.getResource().getCiphertext(), signatureHeader); } private WxPayService getWxPayService(String appid){ WxPayConfig payConfig = new WxPayConfig(); payConfig.setAppId(appid); payConfig.setMchId(StringUtils.trimToNull(this.properties.getMchId())); payConfig.setMchKey(StringUtils.trimToNull(this.properties.getMchKey())); payConfig.setKeyPath(StringUtils.trimToNull(this.properties.getKeyPath())); payConfig.setApiV3Key(StringUtils.trimToNull(this.properties.getAPIv3())); payConfig.setPrivateKeyPath(StringUtils.trimToNull(this.properties.getPrivateKeyPath())); payConfig.setPrivateCertPath(StringUtils.trimToNull(this.properties.getPrivateCertPath())); // 可以指定是否使用沙箱环境 payConfig.setUseSandboxEnv(false); WxPayService wxPayService = new WxPayServiceImpl(); wxPayService.setConfig(payConfig); return wxPayService; } 报错代码 wxPayService.parseOrderNotifyV3Result(payNotifyForm.getResource().getCiphertext(), signatureHeader); 报错输出 java.lang.NullPointerException: null 后台输出的一些参数 [图片]
2023-08-08