repo stringclasses 1k
values | file_url stringlengths 96 373 | file_path stringlengths 11 294 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 6
values | commit_sha stringclasses 1k
values | retrieved_at stringdate 2026-01-04 14:45:56 2026-01-04 18:30:23 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopImgService.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopImgService.java | package cn.binarywang.wx.miniapp.api;
import me.chanjar.weixin.common.bean.result.WxMinishopImageUploadCustomizeResult;
import me.chanjar.weixin.common.error.WxErrorException;
import java.io.File;
/**
* 小程序交易组件-接入商品前必需接口
*
* @author liming1019
*/
public interface WxMaShopImgService {
/**
* 上传图片
*
* @param file
* @return WxMinishopImageUploadCustomizeResult
* @throws WxErrorException
*/
WxMinishopImageUploadCustomizeResult uploadImg(File file) throws WxErrorException;
/**
* 上传图片,带respType参数
*
* @param file
* @param respType
* @return WxMinishopImageUploadCustomizeResult
* @throws WxErrorException
*/
WxMinishopImageUploadCustomizeResult uploadImg(File file, String respType) throws WxErrorException;
/**
* 上传图片链接,带respType参数
*
* @param imgUrl
* @param respType
* @return WxMinishopImageUploadCustomizeResult
* @throws WxErrorException
*/
WxMinishopImageUploadCustomizeResult uploadImg(String imgUrl, String respType) throws WxErrorException;
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaProductOrderService.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaProductOrderService.java | package cn.binarywang.wx.miniapp.api;
import cn.binarywang.wx.miniapp.bean.product.WxMiniBatchGetAfterSaleOrderResponse;
import cn.binarywang.wx.miniapp.bean.product.WxMiniGetAfterSaleOrderResponse;
import cn.binarywang.wx.miniapp.bean.product.WxMiniOrderDeliveryRequest;
import cn.binarywang.wx.miniapp.bean.product.WxMinishopOrderDetailResponse;
import cn.binarywang.wx.miniapp.bean.product.WxMinishopOrderListResponse;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopBaseResponse;
import java.util.List;
import me.chanjar.weixin.common.error.WxErrorException;
/**
* 小程序交易组件-标准版-商品服务
*
* @author boris
*/
public interface WxMaProductOrderService {
/**
* 获取订单列表
*
* @param startCreateTime 否(未填更新时间范围时必填)
* @param endCreateTime 否(未填更新时间范围时必填)
* @param startUpdateTime 否(未填创建时间范围时必填)
* @param endUpdateTime 否(未填创建时间范围时必填)
* @param status 订单状态,枚举值见RequestOrderStatus
* @param page 第几页(最小填1)
* @param pageSize 每页数量(不超过10,000)
* @param source 1:小商店,2:CPS带货
* @return
* @throws WxErrorException
*/
WxMinishopOrderListResponse getOrderList(
String startCreateTime,
String endCreateTime,
String startUpdateTime,
String endUpdateTime,
Integer status,
Integer page,
Integer pageSize,
Integer source
) throws WxErrorException;
/**
* 获取订单详情
*
* @param orderId 订单ID,可从获取订单列表中获得
* @return
*/
WxMinishopOrderDetailResponse getOrderDetail(Long orderId) throws WxErrorException;
/**
* 修改订单备注
* @param orderId 订单id
* @param merchantNotes 备注内容
*/
void changeMerchantNotes(Long orderId,String merchantNotes) throws WxErrorException;
WxMaShopBaseResponse deliverySend(WxMiniOrderDeliveryRequest request)
throws WxErrorException;
WxMiniGetAfterSaleOrderResponse getAfterSaleOrder(Long afterSaleOrderId)
throws WxErrorException;
WxMiniBatchGetAfterSaleOrderResponse batchGetAfterSaleOrder(List<Long> afterSaleOrderIdList)
throws WxErrorException;
WxMaShopBaseResponse afterSaleAccept(Long orderId, Long addressId)
throws WxErrorException;
WxMaShopBaseResponse afterSaleReject(Long afterSaleOrderId, String rejectReason)
throws WxErrorException;
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopDeliveryService.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopDeliveryService.java | package cn.binarywang.wx.miniapp.api;
import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopDeliveryRecieveRequest;
import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopDeliverySendRequest;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopBaseResponse;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopDeliveryGetCompanyListResponse;
import me.chanjar.weixin.common.error.WxErrorException;
/**
* 小程序交易组件-物流发货服务
*
* @author boris
* @author liming1019
*/
public interface WxMaShopDeliveryService {
/**
* 获取快递公司列表
*
* @return WxMaShopDeliveryGetCompanyListResponse
* @throws WxErrorException
*/
WxMaShopDeliveryGetCompanyListResponse getCompanyList() throws WxErrorException;
/**
* 订单发货
*
* @param request
* @return WxMaShopBaseResponse
* @throws WxErrorException
*/
WxMaShopBaseResponse send(WxMaShopDeliverySendRequest request) throws WxErrorException;
/**
* 订单确认收货
*
* @param request
* @return WxMaShopBaseResponse
* @throws WxErrorException
*/
WxMaShopBaseResponse receive(WxMaShopDeliveryRecieveRequest request) throws WxErrorException;
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaMsgService.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaMsgService.java | package cn.binarywang.wx.miniapp.api;
import cn.binarywang.wx.miniapp.bean.WxMaKefuMessage;
import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
import cn.binarywang.wx.miniapp.bean.WxMaUniformMessage;
import cn.binarywang.wx.miniapp.bean.WxMaUpdatableMsg;
import com.google.gson.JsonObject;
import me.chanjar.weixin.common.error.WxErrorException;
/**
* 消息发送接口
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
public interface WxMaMsgService {
/**
* <pre>
* 发送客服消息
* 详情请见: <a href="https://developers.weixin.qq.com/miniprogram/dev/api-backend/customerServiceMessage.send.html">发送客服消息</a>
* 接口url格式:https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=ACCESS_TOKEN
* </pre>
*
* @param message 客服消息
* @return .
* @throws WxErrorException .
*/
boolean sendKefuMsg(WxMaKefuMessage message) throws WxErrorException;
/**
* <pre>
* 发送订阅消息
* https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.send.html
* </pre>
*
* @param subscribeMessage 订阅消息
* @throws WxErrorException .
*/
void sendSubscribeMsg(WxMaSubscribeMessage subscribeMessage) throws WxErrorException;
/**
* <pre>
* 下发小程序和公众号统一的服务消息
* 详情请见: <a href="https://developers.weixin.qq.com/miniprogram/dev/api/open-api/uniform-message/sendUniformMessage.html">下发小程序和公众号统一的服务消息</a>
* 接口url格式:https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send?access_token=ACCESS_TOKEN
* </pre>
*
* @param uniformMessage 消息
* @throws WxErrorException .
*/
void sendUniformMsg(WxMaUniformMessage uniformMessage) throws WxErrorException;
/**
* <pre>
* 创建被分享动态消息的 activity_id.
* 动态消息: https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share/updatable-message.html
*
* 文档地址:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/updatable-message/updatableMessage.createActivityId.html
* 接口地址:GET https://api.weixin.qq.com/cgi-bin/message/wxopen/activityid/create?access_token=ACCESS_TOKEN
* </pre>
*
* @return .
* @throws WxErrorException .
*/
JsonObject createUpdatableMessageActivityId() throws WxErrorException;
/**
* <pre>
* 修改被分享的动态消息.
* 动态消息: https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share/updatable-message.html
*
* 文档地址:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/updatable-message/updatableMessage.setUpdatableMsg.html
* 接口地址:POST https://api.weixin.qq.com/cgi-bin/message/wxopen/activityid/create?access_token=ACCESS_TOKEN
* </pre>
*
* @param msg 动态消息
* @throws WxErrorException .
*/
void setUpdatableMsg(WxMaUpdatableMsg msg) throws WxErrorException;
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaMediaService.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaMediaService.java | package cn.binarywang.wx.miniapp.api;
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.common.error.WxErrorException;
import java.io.File;
import java.io.InputStream;
/**
* <pre>
* 临时素材接口
* Created by Binary Wang on 2016/7/21.
* </pre>
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
public interface WxMaMediaService {
/**
* <pre>
* 新增临时素材
* 小程序可以使用本接口把媒体文件(目前仅支持图片)上传到微信服务器,用户发送客服消息或被动回复用户消息。
* 详情请见: <a href="https://mp.weixin.qq.com/debug/wxadoc/dev/api/custommsg/material.html#新增临时素材">新增临时素材</a>
* 接口url格式:https://api.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE
* </pre>
*
* @param mediaType 媒体类型,
* @param file 文件对象
* @return the wx media upload result
* @throws WxErrorException the wx error exception
* @see #uploadMedia(String, String, InputStream) #uploadMedia(String, String, InputStream)
*/
WxMediaUploadResult uploadMedia(String mediaType, File file) throws WxErrorException;
/**
* <pre>
* 新增临时素材
* 小程序可以使用本接口把媒体文件(目前仅支持图片)上传到微信服务器,用户发送客服消息或被动回复用户消息。
*
* 详情请见: <a href="https://mp.weixin.qq.com/debug/wxadoc/dev/api/custommsg/material.html#新增临时素材">新增临时素材</a>
* 接口url格式:https://api.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE
* </pre>
*
* @param mediaType 媒体类型
* @param fileType 文件类型
* @param inputStream 输入流
* @return the wx media upload result
* @throws WxErrorException the wx error exception
* @see #uploadMedia(String, File) #uploadMedia(java.lang.String, java.io.File)
*/
WxMediaUploadResult uploadMedia(String mediaType, String fileType, InputStream inputStream) throws WxErrorException;
/**
* <pre>
* 获取临时素材
* 小程序可以使用本接口获取客服消息内的临时素材(即下载临时的多媒体文件)。目前小程序仅支持下载图片文件。
*
* 详情请见: <a href="https://mp.weixin.qq.com/debug/wxadoc/dev/api/custommsg/material.html#获取临时素材">获取临时素材</a>
* 接口url格式:https://api.weixin.qq.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID
* </pre>
*
* @param mediaId 媒体Id
* @return 保存到本地的临时文件 media
* @throws WxErrorException the wx error exception
*/
File getMedia(String mediaId) throws WxErrorException;
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaSubscribeService.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaSubscribeService.java | package cn.binarywang.wx.miniapp.api;
import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
import me.chanjar.weixin.common.bean.subscribemsg.CategoryData;
import me.chanjar.weixin.common.bean.subscribemsg.PubTemplateKeyword;
import me.chanjar.weixin.common.bean.subscribemsg.TemplateInfo;
import me.chanjar.weixin.common.bean.subscribemsg.PubTemplateTitleListResult;
import me.chanjar.weixin.common.error.WxErrorException;
import java.util.List;
/**
* 订阅消息类
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* created on 2019-12-15
*/
public interface WxMaSubscribeService {
/**
* <pre>
* 获取账号所属类目下的公共模板标题
*
* 详情请见: <a href="https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.getPubTemplateTitleList.html">获取账号所属类目下的公共模板标题</a>
* 接口url格式: https://api.weixin.qq.com/wxaapi/newtmpl/getpubtemplatetitles?access_token=ACCESS_TOKEN
* </pre>
*
* @param ids 类目 id,多个用逗号隔开
* @param limit 用于分页,表示拉取 limit 条记录。最大为 30。
* @param start 用于分页,表示从 start 开始。从 0 开始计数。
* @return .
* @throws WxErrorException .
*/
PubTemplateTitleListResult getPubTemplateTitleList(String[] ids, int start, int limit) throws WxErrorException;
/**
* <pre>
* 获取模板库某个模板标题下关键词库
*
* 详情请见: <a href="https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.getPubTemplateKeyWordsById.html">获取模板标题下的关键词列表</a>
* 接口url格式: GET https://api.weixin.qq.com/wxaapi/newtmpl/getpubtemplatekeywords?access_token=ACCESS_TOKEN
* </pre>
*
* @param id 模板标题 id,可通过接口获取
* @return .
* @throws WxErrorException .
*/
List<PubTemplateKeyword> getPubTemplateKeyWordsById(String id) throws WxErrorException;
/**
* <pre>
* 组合模板并添加至账号下的个人模板库
*
* 详情请见: <a href="https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.addTemplate.html">获取小程序模板库标题列表</a>
* 接口url格式: POST https://api.weixin.qq.com/wxaapi/newtmpl/addtemplate?access_token=ACCESS_TOKEN
* </pre>
*
* @param id 模板标题 id,可通过接口获取,也可登录小程序后台查看获取
* @param keywordIdList 模板关键词列表
* @param sceneDesc 服务场景描述,15个字以内
* @return 添加至账号下的模板id,发送小程序订阅消息时所需
* @throws WxErrorException .
*/
String addTemplate(String id, List<Integer> keywordIdList, String sceneDesc) throws WxErrorException;
/**
* <pre>
* 获取当前账号下的个人模板列表
*
* 详情请见: <a href="https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.getTemplateList.html">获取当前账号下的个人模板列表</a>
* 接口url格式: GET https://api.weixin.qq.com/wxaapi/newtmpl/gettemplate?access_token=ACCESS_TOKEN
* </pre>
*
* @return .
* @throws WxErrorException .
*/
List<TemplateInfo> getTemplateList() throws WxErrorException;
/**
* <pre>
* 删除账号下的某个模板
*
* 详情请见: <a href="https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.deleteTemplate.html">删除账号下的个人模板</a>
* 接口url格式: POST https://api.weixin.qq.com/wxaapi/newtmpl/deltemplate?access_token=ACCESS_TOKEN
* </pre>
*
* @param templateId 要删除的模板id
* @return 删除是否成功
* @throws WxErrorException .
*/
boolean delTemplate(String templateId) throws WxErrorException;
/**
* <pre>
* 获取小程序账号的类目
* https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.getCategory.html
* GET https://api.weixin.qq.com/wxaapi/newtmpl/getcategory?access_token=ACCESS_TOKEN
* </pre>
*
* @return .
* @throws WxErrorException .
*/
List<CategoryData> getCategory() throws WxErrorException;
/**
* <pre>
* 发送订阅消息
* https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.send.html
* </pre>
*
* @param subscribeMessage 订阅消息
* @throws WxErrorException .
*/
void sendSubscribeMsg(WxMaSubscribeMessage subscribeMessage) throws WxErrorException;
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaExpressService.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaExpressService.java | package cn.binarywang.wx.miniapp.api;
import cn.binarywang.wx.miniapp.bean.express.WxMaExpressAccount;
import cn.binarywang.wx.miniapp.bean.express.WxMaExpressDelivery;
import cn.binarywang.wx.miniapp.bean.express.WxMaExpressPath;
import cn.binarywang.wx.miniapp.bean.express.WxMaExpressPrinter;
import cn.binarywang.wx.miniapp.bean.express.request.*;
import cn.binarywang.wx.miniapp.bean.express.result.WxMaExpressInfoResult;
import cn.binarywang.wx.miniapp.bean.express.result.WxMaExpressOrderInfoResult;
import me.chanjar.weixin.common.error.WxErrorException;
import java.util.List;
/**
* 小程序物流助手
*
* @author <a href="https://github.com/mr-xiaoyu">xiaoyu</a>
* @since 2019-11-26
*/
public interface WxMaExpressService {
/**
* 获取支持的快递公司列表
* <a href="https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/express/by-business/logistics.getAllDelivery.html">查看文档</a>
*
* @return 快递公司列表
* @throws WxErrorException 获取失败时返回
*/
List<WxMaExpressDelivery> getAllDelivery() throws WxErrorException;
/**
* 获取所有绑定的物流账号
* <a href="https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/express/by-business/logistics.getAllAccount.html">查看文档</a>
*
* @return 物流账号list
* @throws WxErrorException 获取失败时返回
*/
List<WxMaExpressAccount> getAllAccount() throws WxErrorException;
/**
* 绑定、解绑物流账号
*
* <a href="https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/express/by-business/logistics.bindAccount.html">查看文档</a>
*
* @param wxMaExpressBindAccountRequest 物流账号对象
* @throws WxErrorException 请求失败时返回
*/
WxMaExpressInfoResult bindAccount(WxMaExpressBindAccountRequest wxMaExpressBindAccountRequest) throws WxErrorException;
/**
* 获取电子面单余额。仅在使用加盟类快递公司时,才可以调用。
* <a href="https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/express/by-business/logistics.getQuota.html">查看文档</a>
*
* @param wxMaExpressBindAccountRequest 物流账号对象
* @return 电子面单余额
* @throws WxErrorException 获取失败时返回
*/
Integer getQuota(WxMaExpressBindAccountRequest wxMaExpressBindAccountRequest) throws WxErrorException;
/**
* 配置面单打印员,可以设置多个,若需要使用微信打单 PC 软件,才需要调用。
*
* <a href="https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/express/by-business/logistics.updatePrinter.html">查看文档</a>
*
* @param wxMaExpressPrinterUpdateRequest 面单打印员对象
* @throws WxErrorException 请求失败时返回
*/
void updatePrinter(WxMaExpressPrinterUpdateRequest wxMaExpressPrinterUpdateRequest) throws WxErrorException;
/**
* 获取打印员。若需要使用微信打单 PC 软件,才需要调用
* <a href="https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/express/by-business/logistics.getPrinter.html">查看文档</a>
*
* @return 打印员
* @throws WxErrorException 获取失败时返回
*/
WxMaExpressPrinter getPrinter() throws WxErrorException;
/**
* 生成运单
* <a href="https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/express/by-business/logistics.addOrder.html">查看文档</a>
*
* @param wxMaExpressAddOrderRequest 生成运单请求对象
* @return 生成运单结果
* @throws WxErrorException 请求失败时返回
*/
WxMaExpressOrderInfoResult addOrder(WxMaExpressAddOrderRequest wxMaExpressAddOrderRequest) throws WxErrorException;
/**
* 批量获取运单数据
*
* <a href="https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/express/by-business/logistics.batchGetOrder.html">查看文档</a>
*
* @param requests 获取运单请求对象集合,最多不能超过1000个
* @return 运单信息集合
* @throws WxErrorException 获取失败时返回
*/
List<WxMaExpressOrderInfoResult> batchGetOrder(List<WxMaExpressGetOrderRequest> requests) throws WxErrorException;
/**
* 取消运单
*
* <a href="https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/express/by-business/logistics.cancelOrder.html">查看文档</a>
*
* @param wxMaExpressGetOrderRequest 运单信息请求对象
* @throws WxErrorException 取消失败时返回
*/
void cancelOrder(WxMaExpressGetOrderRequest wxMaExpressGetOrderRequest) throws WxErrorException;
/**
* 获取运单数据
*
* <a href="https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/express/by-business/logistics.getOrder.html">查看文档</a>
*
* @param wxMaExpressGetOrderRequest 运单信息请求对象
* @return 运单信息
* @throws WxErrorException 获取失败时返回
*/
WxMaExpressOrderInfoResult getOrder(WxMaExpressGetOrderRequest wxMaExpressGetOrderRequest) throws WxErrorException;
/**
* 查询运单轨迹
*
* <a href="https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/express/by-business/logistics.getPath.html">查看文档</a>
*
* @param wxMaExpressGetOrderRequest 运单信息请求对象
* @return 运单轨迹对象
* @throws WxErrorException 查询失败时返回
*/
WxMaExpressPath getPath(WxMaExpressGetOrderRequest wxMaExpressGetOrderRequest) throws WxErrorException;
/**
* 模拟快递公司更新订单状态, 该接口只能用户测试
* <a href="https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/express/by-business/logistics.testUpdateOrder.html">查看文档</a>
*
* @param wxMaExpressTestUpdateOrderRequest 模拟快递公司更新订单状态请求对象
* @throws WxErrorException 模拟更新订单状态失败时返回
*/
void testUpdateOrder(WxMaExpressTestUpdateOrderRequest wxMaExpressTestUpdateOrderRequest) throws WxErrorException;
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaComplaintService.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaComplaintService.java | package cn.binarywang.wx.miniapp.api;
import cn.binarywang.wx.miniapp.bean.complaint.*;
import me.chanjar.weixin.common.error.WxErrorException;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
/**
* 小程序交易投诉接口
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* created on 2025-01-01
*/
public interface WxMaComplaintService {
/**
* <pre>
* 查询投诉单列表API
* 商户可通过调用此接口,查询指定时间段的所有用户投诉信息,以分页输出查询结果。
* 文档详见: https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/guarantee/complaint.html
* </pre>
*
* @param request {@link WxMaComplaintRequest} 查询投诉单列表请求数据
* @return {@link WxMaComplaintResult} 微信返回的投诉单列表
* @throws WxErrorException the wx error exception
*/
WxMaComplaintResult queryComplaints(WxMaComplaintRequest request) throws WxErrorException;
/**
* <pre>
* 查询投诉单详情API
* 商户可通过调用此接口,查询指定投诉单的用户投诉详情,包含投诉内容、投诉关联订单、投诉人联系方式等信息,方便商户处理投诉。
* 文档详见: https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/guarantee/complaint.html
* </pre>
*
* @param request {@link WxMaComplaintDetailRequest} 投诉单详情请求数据
* @return {@link WxMaComplaintDetailResult} 微信返回的投诉单详情
* @throws WxErrorException the wx error exception
*/
WxMaComplaintDetailResult getComplaint(WxMaComplaintDetailRequest request) throws WxErrorException;
/**
* <pre>
* 查询投诉协商历史API
* 商户可通过调用此接口,查询指定投诉的用户商户协商历史,以分页输出查询结果,方便商户根据处理历史来制定后续处理方案。
* 文档详见: https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/guarantee/complaint.html
* </pre>
*
* @param request {@link WxMaNegotiationHistoryRequest} 请求数据
* @return {@link WxMaNegotiationHistoryResult} 微信返回结果
* @throws WxErrorException the wx error exception
*/
WxMaNegotiationHistoryResult queryNegotiationHistorys(WxMaNegotiationHistoryRequest request) throws WxErrorException;
/**
* <pre>
* 创建投诉通知回调地址API
* 商户通过调用此接口创建投诉通知回调URL,当用户产生新投诉且投诉状态已变更时,微信会通过回调URL通知商户。
* 文档详见: https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/guarantee/complaint.html
* </pre>
*
* @param request {@link WxMaComplaintNotifyUrlRequest} 请求数据
* @return {@link WxMaComplaintNotifyUrlResult} 微信返回结果
* @throws WxErrorException the wx error exception
*/
WxMaComplaintNotifyUrlResult addComplaintNotifyUrl(WxMaComplaintNotifyUrlRequest request) throws WxErrorException;
/**
* <pre>
* 查询投诉通知回调地址API
* 商户通过调用此接口查询投诉通知的回调URL。
* 文档详见: https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/guarantee/complaint.html
* </pre>
*
* @return {@link WxMaComplaintNotifyUrlResult} 微信返回结果
* @throws WxErrorException the wx error exception
*/
WxMaComplaintNotifyUrlResult getComplaintNotifyUrl() throws WxErrorException;
/**
* <pre>
* 更新投诉通知回调地址API
* 商户通过调用此接口更新投诉通知的回调URL。
* 文档详见: https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/guarantee/complaint.html
* </pre>
*
* @param request {@link WxMaComplaintNotifyUrlRequest} 请求数据
* @return {@link WxMaComplaintNotifyUrlResult} 微信返回结果
* @throws WxErrorException the wx error exception
*/
WxMaComplaintNotifyUrlResult updateComplaintNotifyUrl(WxMaComplaintNotifyUrlRequest request) throws WxErrorException;
/**
* <pre>
* 删除投诉通知回调地址API
* 当商户不再需要推送通知时,可通过调用此接口删除投诉通知的回调URL,取消通知回调。
* 文档详见: https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/guarantee/complaint.html
* </pre>
*
* @throws WxErrorException the wx error exception
*/
void deleteComplaintNotifyUrl() throws WxErrorException;
/**
* <pre>
* 提交回复API
* 商户可通过调用此接口,提交回复内容。其中上传图片凭证需首先调用商户上传反馈图片接口,得到图片id,再将id填入请求。
* 回复可配置文字链,传入跳转链接文案和跳转链接字段,用户点击即可跳转对应页面
* 文档详见: https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/guarantee/complaint.html
* </pre>
*
* @param request {@link WxMaResponseRequest} 请求数据
* @throws WxErrorException the wx error exception
*/
void submitResponse(WxMaResponseRequest request) throws WxErrorException;
/**
* <pre>
* 反馈处理完成API
* 商户可通过调用此接口,反馈投诉单已处理完成。
* 文档详见: https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/guarantee/complaint.html
* </pre>
*
* @param request {@link WxMaCompleteRequest} 请求数据
* @throws WxErrorException the wx error exception
*/
void complete(WxMaCompleteRequest request) throws WxErrorException;
/**
* <pre>
* 商户上传反馈图片API
* 商户可通过调用此接口上传反馈图片凭证,上传成功后可在提交回复时使用。
* 文档详见: https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/guarantee/complaint.html
* </pre>
*
* @param imageFile 需要上传的图片文件
* @return String 微信返回的媒体文件标识Id
* @throws WxErrorException the wx error exception
* @throws IOException IO异常
*/
String uploadResponseImage(File imageFile) throws WxErrorException, IOException;
/**
* <pre>
* 商户上传反馈图片API
* 商户可通过调用此接口上传反馈图片凭证,上传成功后可在提交回复时使用。
* 文档详见: https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/guarantee/complaint.html
* </pre>
*
* @param inputStream 需要上传的图片文件流
* @param fileName 需要上传的图片文件名
* @return String 微信返回的媒体文件标识Id
* @throws WxErrorException the wx error exception
* @throws IOException IO异常
*/
String uploadResponseImage(InputStream inputStream, String fileName) throws WxErrorException, IOException;
} | java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaSettingService.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaSettingService.java | package cn.binarywang.wx.miniapp.api;
import cn.binarywang.wx.miniapp.bean.WxMaDomainAction;
import me.chanjar.weixin.common.error.WxErrorException;
/**
* 小程序修改服务器地址、成员管理 API(大部分只能是第三方平台调用)
*
* @author <a href="https://github.com/charmingoh">Charming</a>
* @since 2018-04-27 15:46
*/
public interface WxMaSettingService {
/**
* 操作服务器域名
*
* @param domainAction 域名操作参数
* 除了 webViewDomain,都是有效的
* @return 以下字段仅在 get 时返回完整字段
* @throws WxErrorException 操作失败时抛出,具体错误码请看文档
*/
WxMaDomainAction modifyDomain(WxMaDomainAction domainAction) throws WxErrorException;
/**
* 设置小程序业务域名(仅供第三方代小程序调用)
* 授权给第三方的小程序,其业务域名只可以为第三方的服务器,
* 当小程序通过第三方发布代码上线后,小程序原先自己配置的业务域名将被删除,
* 只保留第三方平台的域名,所以第三方平台在代替小程序发布代码之前,需要调用接口为小程序添加业务域名。
* 提示:需要先将域名登记到第三方平台的小程序业务域名中,才可以调用接口进行配置。
*
* @param domainAction 域名操作参数
* 只有 action 和 webViewDomain 是有效的
* @return 以下字段仅在 get 时返回完整字段
* @throws WxErrorException 操作失败时抛出,具体错误码请看文档
*/
WxMaDomainAction setWebViewDomain(WxMaDomainAction domainAction) throws WxErrorException;
/**
* 绑定微信用户为小程序体验者
*
* @param wechatId 微信号
* @throws WxErrorException 失败时抛出,具体错误码请看文档
*/
void bindTester(String wechatId) throws WxErrorException;
/**
* 解除绑定小程序的体验者
*
* @param wechatId 微信号
* @throws WxErrorException 失败时抛出,具体错误码请看文档
*/
void unbindTester(String wechatId) throws WxErrorException;
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopOrderService.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopOrderService.java | package cn.binarywang.wx.miniapp.api;
import cn.binarywang.wx.miniapp.bean.shop.WxMaShopOrderInfo;
import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopOrderPayRequest;
import cn.binarywang.wx.miniapp.bean.shop.response.*;
import me.chanjar.weixin.common.error.WxErrorException;
import java.util.Date;
/**
* 小程序交易组件-订单服务
*
* @author boris
*/
public interface WxMaShopOrderService {
Boolean checkScene(Integer scene) throws WxErrorException;
WxMaShopAddOrderResponse addOrder(WxMaShopOrderInfo orderInfo) throws WxErrorException;
WxMaShopBaseResponse orderPay(WxMaShopOrderPayRequest request) throws WxErrorException;
WxMaShopGetOrderResponse getOrder(Long orderId, String outOrderId, String openid)
throws WxErrorException;
/**
* <pre>
*
* 获取订单列表
*
* 请求方式:POST(HTTPS)
* 请求地址:<a href="https://api.weixin.qq.com/shop/order/get_list">请求地址</a>
*
* 文档地址:<a href="https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/ministore/minishopopencomponent2/API/order/get_order_list.html">文档地址</a>
* </pre>
*
* @param page 第x页,大于等于1
* @param pageSize 每页订单数,上限100
* @param desc 是否时间倒叙
* @param startCreateTime 起始创建时间
* @param endCreateTime 最终创建时间
* @return 订单列表信息
* @throws WxErrorException .
*/
WxMaShopGetOrderListResponse getOrderList(Integer page, Integer pageSize, Boolean desc, Date startCreateTime, Date endCreateTime)
throws WxErrorException;
/**
* <pre>
*
* 生成支付参数
*
* 请求方式:POST(HTTPS)
* 请求地址:<a href="https://api.weixin.qq.com/shop/order/getpaymentparams">请求地址</a>
*
* 文档地址:<a href="https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/ministore/minishopopencomponent2/API/order/getpaymentparams.html">文档地址</a>
* </pre>
*
* @param orderId 微信侧订单id
* @param outOrderId 商家自定义订单ID
* @param openid 用户openid
* @return 支付参数
* @throws WxErrorException .
*/
WxMaShopGetPaymentParamsResponse getPaymentParams(String orderId, String outOrderId, String openid) throws WxErrorException;
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaCodeService.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaCodeService.java | package cn.binarywang.wx.miniapp.api;
import cn.binarywang.wx.miniapp.bean.code.*;
import me.chanjar.weixin.common.error.WxErrorException;
import java.util.List;
/**
* 小程序代码管理相关 API(大部分只能是第三方平台调用)
* 文档:https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1489140610_Uavc4&token=&lang=zh_CN
*
* @author <a href="https://github.com/charmingoh">Charming</a>
* @since 2018-04-26 19:43
*/
public interface WxMaCodeService {
/**
* 为授权的小程序帐号上传小程序代码(仅仅支持第三方开放平台).
*
* @param commitRequest 参数
* @throws WxErrorException 上传失败时抛出,具体错误码请看类注释文档
*/
void commit(WxMaCodeCommitRequest commitRequest) throws WxErrorException;
/**
* 获取体验小程序的体验二维码.
* 文档地址:
* https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1489140610_Uavc4&token=&lang=zh_CN
*
* @param path 指定体验版二维码跳转到某个具体页面(如果不需要的话,则不需要填path参数,可在路径后以“?参数”方式传入参数)
* 具体的路径加参数需要urlencode(方法内部处理),比如page/index?action=1编码后得到page%2Findex%3Faction%3D1
* @return 二维码 bytes
* @throws WxErrorException 上传失败时抛出,具体错误码请看类注释文档
*/
byte[] getQrCode(String path) throws WxErrorException;
/**
* 获取授权小程序帐号的可选类目.
*
* @return List<WxMaCategory>
* @throws WxErrorException 获取失败时返回,具体错误码请看此接口的注释文档
*/
List<WxMaCodeSubmitAuditItem> getCategory() throws WxErrorException;
/**
* 获取小程序的第三方提交代码的页面配置(仅供第三方开发者代小程序调用).
*
* @return page_list 页面配置列表
* @throws WxErrorException 获取失败时返回,具体错误码请看此接口的注释文档
*/
List<String> getPage() throws WxErrorException;
/**
* 将第三方提交的代码包提交审核(仅供第三方开发者代小程序调用).
*
* @param auditRequest 提交审核参数
* @return 审核编号
* @throws WxErrorException 提交失败时返回,具体错误码请看此接口的注释文档
*/
long submitAudit(WxMaCodeSubmitAuditRequest auditRequest) throws WxErrorException;
/**
* 查询某个指定版本的审核状态(仅供第三方代小程序调用).
*
* @param auditId 提交审核时获得的审核id
* @return 审核状态
* @throws WxErrorException 查询失败时返回,具体错误码请看此接口的注释文档
*/
WxMaCodeAuditStatus getAuditStatus(long auditId) throws WxErrorException;
/**
* 查询最新一次提交的审核状态(仅供第三方代小程序调用).
* 文档:<a href="https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/miniprogram-management/code-management/getLatestAuditStatus.html">文档地址</a>
* @return 审核状态
* @throws WxErrorException 查询失败时返回,具体错误码请看此接口的注释文档
*/
WxMaCodeAuditStatus getLatestAuditStatus() throws WxErrorException;
/**
* 发布已通过审核的小程序(仅供第三方代小程序调用).
*
* @throws WxErrorException 发布失败时抛出,具体错误码请看此接口的注释文档
*/
void release() throws WxErrorException;
/**
* 修改小程序线上代码的可见状态(仅供第三方代小程序调用).
*
* @param action 设置可访问状态,发布后默认可访问,close为不可见,open为可见
* @throws WxErrorException 发布失败时抛出,具体错误码请看此接口的注释文档
*/
void changeVisitStatus(String action) throws WxErrorException;
/**
* 小程序版本回退(仅供第三方代小程序调用).
*
* @throws WxErrorException 失败时抛出,具体错误码请看此接口的注释文档
*/
void revertCodeRelease() throws WxErrorException;
/**
* 查询当前设置的最低基础库版本及各版本用户占比 (仅供第三方代小程序调用).
*
* @return 小程序版本分布信息
* @throws WxErrorException 失败时抛出,具体错误码请看此接口的注释文档
*/
WxMaCodeVersionDistribution getSupportVersion() throws WxErrorException;
/**
* 查询小程序版本信息
*
* @return 小程序的体验版和线上版本信息
* @throws WxErrorException 失败时抛出,具体错误码请看此接口的注释文档
*/
WxMaCodeVersionInfo getVersionInfo() throws WxErrorException;
/**
* 设置最低基础库版本(仅供第三方代小程序调用).
*
* @param version 版本
* @throws WxErrorException 失败时抛出,具体错误码请看此接口的注释文档
*/
void setSupportVersion(String version) throws WxErrorException;
/**
* 小程序审核撤回.
* 单个帐号每天审核撤回次数最多不超过1次,一个月不超过10次
*
* @throws WxErrorException 失败时抛出,具体错误码请看此接口的注释文档
*/
void undoCodeAudit() throws WxErrorException;
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaMarketingService.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaMarketingService.java | package cn.binarywang.wx.miniapp.api;
import cn.binarywang.wx.miniapp.bean.marketing.WxMaUserAction;
import me.chanjar.weixin.common.error.WxErrorException;
import java.util.List;
/**
*
* 微信营销接口
* @author <a href="https://github.com/184759547">184759547</a>
* @since : 2021/12/28
*/
public interface WxMaMarketingService {
/**
* <pre>
* 创建数据源.
* 接口调用请求说明
* https://ad.weixin.qq.com/guide/457
* </pre>
*
* @param type 用户行为源类型
* @param name 用户行为源名称 必填
* @param description 用户行为源描述,字段长度最小 1 字节,长度最大 128 字节
*/
long addUserActionSets(String type, String name, String description) throws WxErrorException;
/**
* 回传数据.
* 接口调用请求说明
* https://ad.weixin.qq.com/guide/457
*
* @param actions 用户行为源类型
*/
String addUserAction(List<WxMaUserAction> actions, Long userActionSetId) throws WxErrorException;
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaReimburseInvoiceService.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaReimburseInvoiceService.java | package cn.binarywang.wx.miniapp.api;
import cn.binarywang.wx.miniapp.bean.invoice.reimburse.*;
import me.chanjar.weixin.common.error.WxErrorException;
import java.util.List;
/**
* 电子发票报销方相关接口
* 接口文档: https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/E_Invoice/Reimburser_API_List.html
* @author <a href="https://github.com/mr-xiaoyu">xiaoyu</a>
* @since 2021-06-10
*/
public interface WxMaReimburseInvoiceService {
/**
* 查询报销发票信息
* @param request {@link InvoiceInfoRequest} 查询报销发票信息参数
* @return {@link InvoiceInfoResponse} 查询结果
* @throws WxErrorException 查询失败时
*/
InvoiceInfoResponse getInvoiceInfo(InvoiceInfoRequest request) throws WxErrorException;
/**
* 批量查询报销发票信息
* @param request {@link InvoiceBatchRequest} 批量查询报销发票信息参数对象
* @return {@link InvoiceInfoResponse} 查询结果列表
* @throws WxErrorException 查询失败时
*/
List<InvoiceInfoResponse> getInvoiceBatch(InvoiceBatchRequest request) throws WxErrorException;
/**
* 更新发票状态
* @param request {@link UpdateInvoiceStatusRequest} 更新发票状态参数
* @throws WxErrorException 更新失败时
*/
void updateInvoiceStatus(UpdateInvoiceStatusRequest request) throws WxErrorException;
/**
* 批量更新发票状态
* @param request {@link UpdateStatusBatchRequest} 批量更新发票状态参数
* @throws WxErrorException 更新失败时
*/
void updateStatusBatch(UpdateStatusBatchRequest request) throws WxErrorException;
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaProductService.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaProductService.java | package cn.binarywang.wx.miniapp.api;
import cn.binarywang.wx.miniapp.bean.product.WxMinishopAddGoodsSkuData;
import cn.binarywang.wx.miniapp.bean.product.WxMinishopAddGoodsSpuData;
import cn.binarywang.wx.miniapp.bean.product.WxMinishopGetBrandResponse;
import cn.binarywang.wx.miniapp.bean.product.WxMinishopGetCategoryResponse;
import cn.binarywang.wx.miniapp.bean.product.WxMinishopGetFrightTemplateResponse;
import cn.binarywang.wx.miniapp.bean.product.WxMinishopResult;
import cn.binarywang.wx.miniapp.bean.product.WxMinishopSku;
import cn.binarywang.wx.miniapp.bean.product.WxMinishopSkuListResponse;
import cn.binarywang.wx.miniapp.bean.product.WxMinishopSpu;
import cn.binarywang.wx.miniapp.bean.product.WxMinishopSpuGetResponse;
import cn.binarywang.wx.miniapp.bean.product.WxMinishopSpuListResponse;
import cn.binarywang.wx.miniapp.bean.product.WxMinishopUpdateGoodsSkuData;
import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopSpuPageRequest;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopBaseResponse;
import java.io.File;
import java.util.List;
import me.chanjar.weixin.common.bean.result.WxMinishopImageUploadResult;
import me.chanjar.weixin.common.error.WxErrorException;
/**
* 小程序交易组件-商品服务
*
* @author boris
*/
public interface WxMaProductService {
WxMinishopImageUploadResult uploadImg(File file, Integer respType, Integer width, Integer height) throws WxErrorException;
WxMinishopImageUploadResult uploadImg(String imgUrl, Integer respType) throws WxErrorException;
WxMinishopGetCategoryResponse getCategory(Integer fCatId) throws WxErrorException;
WxMinishopGetBrandResponse getBrand() throws WxErrorException;
WxMinishopGetFrightTemplateResponse getFreightTemplate() throws WxErrorException;
WxMinishopResult<WxMinishopAddGoodsSpuData> addSpu(WxMinishopSpu spuInfo) throws WxErrorException;
WxMaShopBaseResponse deleteSpu(Integer productId, String outProductId) throws WxErrorException;
WxMinishopSpuGetResponse getSpu(Integer productId, String outProductId, Integer needEditSpu)
throws WxErrorException;
WxMinishopSpuListResponse getSpuList(WxMaShopSpuPageRequest request)
throws WxErrorException;
WxMinishopResult<WxMinishopAddGoodsSpuData> updateSpu(WxMinishopSpu spuInfo) throws WxErrorException;
WxMaShopBaseResponse listingSpu(Integer productId, String outProductId)
throws WxErrorException;
WxMaShopBaseResponse delistingSpu(Integer productId, String outProductId)
throws WxErrorException;
WxMinishopSkuListResponse getSkuList(Long productId, Integer needRealStock, Integer needEditSku)
throws WxErrorException;
/**
* 小商店新增sku信息
*
* @param sku
* @return
* @throws WxErrorException
*/
WxMinishopResult<WxMinishopAddGoodsSkuData> minishiopGoodsAddSku(WxMinishopSku sku) throws WxErrorException;
/**
* 小商店批量新增sku信息
*
* @param skuList
* @return
* @throws WxErrorException
*/
WxMinishopResult<List<WxMinishopAddGoodsSkuData>> minishopGoodsBatchAddSku(List<WxMinishopSku> skuList) throws WxErrorException;
/**
* 小商店删除sku消息
*
* @param productId
* @param outProductId
* @param outSkuId
* @param skuId
* @return
* @throws WxErrorException
*/
WxMaShopBaseResponse minishopGoodsDelSku(Long productId, Long outProductId, String outSkuId, Long skuId) throws WxErrorException;
/**
* 小商店更新sku
*
* @param sku
* @return
* @throws WxErrorException
*/
WxMinishopResult<WxMinishopUpdateGoodsSkuData> minishopGoodsUpdateSku(WxMinishopSku sku) throws WxErrorException;
/**
* 小商店更新sku价格
*
* @param productId
* @param outProductId
* @param outSkuId
* @param skuId
* @param salePrice
* @param marketPrice
* @return
* @throws WxErrorException
*/
WxMinishopResult<WxMinishopUpdateGoodsSkuData> minishopGoodsUpdateSkuPrice(Long productId,
String outProductId, String outSkuId, Long skuId, Long salePrice, Long marketPrice) throws WxErrorException;
/**
* 小商店更新sku库存
*
* @param productId
* @param outProductId
* @param outSkuId
* @param skuId
* @param type
* @param stockNum
* @return
* @throws WxErrorException
*/
WxMinishopResult<WxMinishopUpdateGoodsSkuData> minishopGoodsUpdateSkuStock(Long productId,
String outProductId, String outSkuId, Long skuId, Integer type, Integer stockNum) throws WxErrorException;
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShareService.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShareService.java | package cn.binarywang.wx.miniapp.api;
import cn.binarywang.wx.miniapp.bean.WxMaGroupEnterInfo;
import cn.binarywang.wx.miniapp.bean.WxMaShareInfo;
/**
* 分享信息相关操作接口.
*
* @author zhfish
*/
public interface WxMaShareService {
/**
* 解密分享敏感数据.
*
* @param sessionKey 会话密钥
* @param encryptedData 消息密文
* @param ivStr 加密算法的初始向量
*/
WxMaShareInfo getShareInfo(String sessionKey, String encryptedData, String ivStr);
/**
* 解密群入口敏感数据.
* 对应 wx.getGroupEnterInfo 接口返回的 encryptedData 解密
*
* @param sessionKey 会话密钥
* @param encryptedData 消息密文
* @param ivStr 加密算法的初始向量
* @return 群入口信息
* @see <a href="https://developers.weixin.qq.com/miniprogram/dev/api/open-api/group/wx.getGroupEnterInfo.html">wx.getGroupEnterInfo 官方文档</a>
*/
WxMaGroupEnterInfo getGroupEnterInfo(String sessionKey, String encryptedData, String ivStr);
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopCouponService.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopCouponService.java | package cn.binarywang.wx.miniapp.api;
import cn.binarywang.wx.miniapp.bean.shop.WxMaShopCouponInfo;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopBaseResponse;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopCouponListResponse;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopCouponResponse;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopUserCouponListResponse;
import me.chanjar.weixin.common.error.WxErrorException;
/**
* @author leiin
* created on 2022/7/1 2:49 下午
*/
public interface WxMaShopCouponService {
WxMaShopBaseResponse addCoupon(WxMaShopCouponInfo couponInfo) throws WxErrorException;
WxMaShopCouponResponse getCoupon(String outCouponId) throws WxErrorException;
WxMaShopCouponListResponse getCouponList(Integer pageSize,
Integer offset) throws WxErrorException;
WxMaShopBaseResponse updateCoupon(WxMaShopCouponInfo couponInfo) throws WxErrorException;
WxMaShopBaseResponse updateCouponStatus(String outCouponId,
Integer status) throws WxErrorException;
WxMaShopBaseResponse updateCouponStock(String outCouponId, Integer isUsedNum, Integer receiveNum) throws WxErrorException;
WxMaShopBaseResponse addUserCoupon(String openid, String outUserCouponId,
String outCouponId, Integer status, Long recvTime) throws WxErrorException;
WxMaShopUserCouponListResponse getUserCouponList(Integer pageSize, Integer offset, String openid) throws WxErrorException;
WxMaShopBaseResponse updateUserCoupon(String openid, String outUserCouponId,
String outCouponId, Long useTime, Long recvTime) throws WxErrorException;
WxMaShopBaseResponse updateUserCouponStatus(String openid, String outUserCouponId,
String outCouponId, Integer status) throws WxErrorException;
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaQrcodeService.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaQrcodeService.java | package cn.binarywang.wx.miniapp.api;
import cn.binarywang.wx.miniapp.bean.WxMaCodeLineColor;
import me.chanjar.weixin.common.error.WxErrorException;
import java.io.File;
/**
* <pre>
* 二维码相关操作接口.
*
* 接口A(createWxaCode)加上接口C(createQrcode),总共生成的码数量限制为100,000,请谨慎调用。
*
* 文档地址1:https://mp.weixin.qq.com/debug/wxadoc/dev/api/qrcode.html
* 文档地址2:https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/qr-code.html
* </pre>
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
public interface WxMaQrcodeService {
/**
* 接口C: 获取小程序页面二维码.
* <pre>
* 适用于需要的码数量较少的业务场景
* 通过该接口,仅能生成已发布的小程序的二维码。
* 可以在开发者工具预览时生成开发版的带参二维码。
* 带参二维码只有 100000 个,请谨慎调用。
* </pre>
*
* @param path 不能为空,最大长度 128 字节
* @param width 默认430 二维码的宽度
* @return 文件内容字节数组
* @throws WxErrorException 异常
*/
byte[] createQrcodeBytes(String path, int width) throws WxErrorException;
/**
* 接口C: 获取小程序页面二维码.
* <pre>
* 适用于需要的码数量较少的业务场景
* 通过该接口,仅能生成已发布的小程序的二维码。
* 可以在开发者工具预览时生成开发版的带参二维码。
* 带参二维码只有 100000 个,请谨慎调用。
* </pre>
*
* @param path 不能为空,最大长度 128 字节
* @param width 默认430 二维码的宽度
* @param filePath 二维码生成的文件路径,例如: /var/temp
* @return 文件对象
* @throws WxErrorException 异常
*/
File createQrcode(String path, int width, String filePath) throws WxErrorException;
/**
* 接口C: 获取小程序页面二维码.
* <pre>
* 适用于需要的码数量较少的业务场景
* 通过该接口,仅能生成已发布的小程序的二维码。
* 可以在开发者工具预览时生成开发版的带参二维码。
* 带参二维码只有 100000 个,请谨慎调用。
* </pre>
*
* @param path 不能为空,最大长度 128 字节
* @param width 默认430 二维码的宽度
* @return 文件对象
* @throws WxErrorException 异常
*/
File createQrcode(String path, int width) throws WxErrorException;
/**
* 接口C: 获取小程序页面二维码.
* <pre>
* 适用于需要的码数量较少的业务场景
* 通过该接口,仅能生成已发布的小程序的二维码。
* 可以在开发者工具预览时生成开发版的带参二维码。
* 带参二维码只有 100000 个,请谨慎调用。
* </pre>
*
* @param path 不能为空,最大长度 128 字节
* @param filePath 二维码生成的文件路径,例如: /var/temp
* @return 文件对象
* @throws WxErrorException 异常
*/
File createQrcode(String path, String filePath) throws WxErrorException;
/**
* 接口C: 获取小程序页面二维码.
* <pre>
* 适用于需要的码数量较少的业务场景
* 通过该接口,仅能生成已发布的小程序的二维码。
* 可以在开发者工具预览时生成开发版的带参二维码。
* 带参二维码只有 100000 个,请谨慎调用。
* </pre>
*
* @param path 不能为空,最大长度 128 字节
* @return 文件对象
* @throws WxErrorException 异常
*/
File createQrcode(String path) throws WxErrorException;
/**
* 接口A: 获取小程序码.
*
* @param path 不能为空,最大长度 128 字节
* @param envVersion 默认"release" 要打开的小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop"
* @param width 默认430 二维码的宽度
* @param autoColor 默认true 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调
* @param lineColor autoColor 为 false 时生效,使用 rgb 设置颜色 例如 {"r":"xxx","g":"xxx","b":"xxx"}
* @param isHyaline 是否需要透明底色, isHyaline 为true时,生成透明底色的小程序码
* @return 文件内容字节数组
* @throws WxErrorException 异常
*/
byte[] createWxaCodeBytes(String path, String envVersion, int width, boolean autoColor, WxMaCodeLineColor lineColor,
boolean isHyaline) throws WxErrorException;
/**
* 接口A: 获取小程序码.
*
* @param path 不能为空,最大长度 128 字节
* @param envVersion 默认"release" 要打开的小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop"
* @param width 默认430 二维码的宽度
* @param filePath 二维码生成的文件路径,例如: /var/temp
* @param autoColor 默认true 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调
* @param lineColor autoColor 为 false 时生效,使用 rgb 设置颜色 例如 {"r":"xxx","g":"xxx","b":"xxx"}
* @param isHyaline 是否需要透明底色, isHyaline 为true时,生成透明底色的小程序码
* @return 文件对象
* @throws WxErrorException 异常
*/
File createWxaCode(String path, String envVersion, int width, String filePath, boolean autoColor,
WxMaCodeLineColor lineColor, boolean isHyaline) throws WxErrorException;
/**
* 接口A: 获取小程序码.
*
* @param path 不能为空,最大长度 128 字节
* @param envVersion 默认"release" 要打开的小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop"
* @param width 默认430 二维码的宽度
* @param autoColor 默认true 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调
* @param lineColor autoColor 为 false 时生效,使用 rgb 设置颜色 例如 {"r":"xxx","g":"xxx","b":"xxx"}
* @param isHyaline 是否需要透明底色, isHyaline 为true时,生成透明底色的小程序码
* @return 文件对象
* @throws WxErrorException 异常
*/
File createWxaCode(String path, String envVersion, int width, boolean autoColor, WxMaCodeLineColor lineColor,
boolean isHyaline) throws WxErrorException;
/**
* 接口A: 获取小程序码.
*
* @param path 不能为空,最大长度 128 字节
* @param width 默认430 二维码的宽度
* @param filePath 二维码生成的文件路径,例如: /var/temp
* @return 文件对象
* @throws WxErrorException 异常
*/
File createWxaCode(String path, int width, String filePath) throws WxErrorException;
/**
* 接口A: 获取小程序码.
*
* @param path 不能为空,最大长度 128 字节
* @param width 默认430 二维码的宽度
* @return 文件对象
* @throws WxErrorException 异常
*/
File createWxaCode(String path, int width) throws WxErrorException;
/**
* 接口A: 获取小程序码.
*
* @param path 不能为空,最大长度 128 字节
* @param filePath 二维码生成的文件路径,例如: /var/temp
* @return 文件对象
* @throws WxErrorException 异常
*/
File createWxaCode(String path, String filePath) throws WxErrorException;
/**
* 接口A: 获取小程序码.
*
* @param path 不能为空,最大长度 128 字节
* @return 文件对象
* @throws WxErrorException 异常
*/
File createWxaCode(String path) throws WxErrorException;
/**
* 接口B: 获取小程序码(永久有效、数量暂无限制).
* <pre>
* 通过该接口生成的小程序码,永久有效,数量暂无限制。
* 用户扫描该码进入小程序后,将统一打开首页,开发者需在对应页面根据获取的码中 scene 字段的值,再做处理逻辑。
* 使用如下代码可以获取到二维码中的 scene 字段的值。
* 调试阶段可以使用开发工具的条件编译自定义参数 scene=xxxx 进行模拟,开发工具模拟时的 scene 的参数值需要进行 urlencode
* </pre>
*
* @param scene 最大32个可见字符,只支持数字,大小写英文以及部分特殊字符:!#$&'()*+,/:;=?@-._~,
* 其它字符请自行编码为合法字符(因不支持%,中文无法使用 urlencode 处理,请使用其他编码方式)
* @param page 必须是已经发布的小程序页面,例如 "pages/index/index" ,如果不填写这个字段,默认跳主页面
* @param checkPath 默认true 检查 page 是否存在,为 true 时 page 必须是已经发布的小程序存在的页面(否则报错);
* 为 false 时允许小程序未发布或者 page 不存在,但 page 有数量上限(60000个)请勿滥用
* @param envVersion 默认"release" 要打开的小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop"
* @param width 默认430 二维码的宽度
* @param autoColor 默认true 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调
* @param lineColor autoColor 为 false 时生效,使用 rgb 设置颜色 例如 {"r":"xxx","g":"xxx","b":"xxx"}
* @param isHyaline 是否需要透明底色, is_hyaline 为true时,生成透明底色的小程序码
* @return 文件内容字节数组
* @throws WxErrorException 异常
*/
byte[] createWxaCodeUnlimitBytes(String scene, String page, boolean checkPath, String envVersion, int width, boolean autoColor,
WxMaCodeLineColor lineColor, boolean isHyaline) throws WxErrorException;
/**
* 接口B: 获取小程序码(永久有效、数量暂无限制).
* <pre>
* 通过该接口生成的小程序码,永久有效,数量暂无限制。
* 用户扫描该码进入小程序后,将统一打开首页,开发者需在对应页面根据获取的码中 scene 字段的值,再做处理逻辑。
* 使用如下代码可以获取到二维码中的 scene 字段的值。
* 调试阶段可以使用开发工具的条件编译自定义参数 scene=xxxx 进行模拟,开发工具模拟时的 scene 的参数值需要进行 urlencode
* </pre>
*
* @param scene 最大32个可见字符,只支持数字,大小写英文以及部分特殊字符:!#$&'()*+,/:;=?@-._~,
* 其它字符请自行编码为合法字符(因不支持%,中文无法使用 urlencode 处理,请使用其他编码方式)
* @param page 必须是已经发布的小程序页面,例如 "pages/index/index" ,如果不填写这个字段,默认跳主页面
* @param filePath 二维码生成的文件路径,例如: /var/temp
* @param checkPath 默认true 检查 page 是否存在,为 true 时 page 必须是已经发布的小程序存在的页面(否则报错);
* 为 false 时允许小程序未发布或者 page 不存在,但 page 有数量上限(60000个)请勿滥用
* @param envVersion 默认"release" 要打开的小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop"
* @param width 默认430 二维码的宽度
* @param autoColor 默认true 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调
* @param lineColor autoColor 为 false 时生效,使用 rgb 设置颜色 例如 {"r":"xxx","g":"xxx","b":"xxx"}
* @param isHyaline 是否需要透明底色, is_hyaline 为true时,生成透明底色的小程序码
* @return 文件对象
* @throws WxErrorException 异常
*/
File createWxaCodeUnlimit(String scene, String page, String filePath, boolean checkPath, String envVersion, int width,
boolean autoColor, WxMaCodeLineColor lineColor, boolean isHyaline) throws WxErrorException;
/**
* 接口B: 获取小程序码(永久有效、数量暂无限制).
* <pre>
* 通过该接口生成的小程序码,永久有效,数量暂无限制。
* 用户扫描该码进入小程序后,将统一打开首页,开发者需在对应页面根据获取的码中 scene 字段的值,再做处理逻辑。
* 使用如下代码可以获取到二维码中的 scene 字段的值。
* 调试阶段可以使用开发工具的条件编译自定义参数 scene=xxxx 进行模拟,开发工具模拟时的 scene 的参数值需要进行 urlencode
* </pre>
*
* @param scene 最大32个可见字符,只支持数字,大小写英文以及部分特殊字符:!#$&'()*+,/:;=?@-._~,
* 其它字符请自行编码为合法字符(因不支持%,中文无法使用 urlencode 处理,请使用其他编码方式)
* @param page 必须是已经发布的小程序页面,例如 "pages/index/index" ,如果不填写这个字段,默认跳主页面
* @param checkPath 默认true 检查 page 是否存在,为 true 时 page 必须是已经发布的小程序存在的页面(否则报错);
* 为 false 时允许小程序未发布或者 page 不存在,但 page 有数量上限(60000个)请勿滥用
* @param envVersion 默认"release" 要打开的小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop"
* @param width 默认430 二维码的宽度
* @param autoColor 默认true 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调
* @param lineColor autoColor 为 false 时生效,使用 rgb 设置颜色 例如 {"r":"xxx","g":"xxx","b":"xxx"}
* @param isHyaline 是否需要透明底色, is_hyaline 为true时,生成透明底色的小程序码
* @return 文件对象
* @throws WxErrorException 异常
*/
File createWxaCodeUnlimit(String scene, String page, boolean checkPath, String envVersion, int width, boolean autoColor,
WxMaCodeLineColor lineColor, boolean isHyaline) throws WxErrorException;
/**
* 接口B: 获取小程序码(永久有效、数量暂无限制).
* <pre>
* 通过该接口生成的小程序码,永久有效,数量暂无限制。
* 用户扫描该码进入小程序后,将统一打开首页,开发者需在对应页面根据获取的码中 scene 字段的值,再做处理逻辑。
* 使用如下代码可以获取到二维码中的 scene 字段的值。
* 调试阶段可以使用开发工具的条件编译自定义参数 scene=xxxx 进行模拟,开发工具模拟时的 scene 的参数值需要进行 urlencode
* </pre>
*
* @param scene 最大32个可见字符,只支持数字,大小写英文以及部分特殊字符:!#$&'()*+,/:;=?@-._~,
* 其它字符请自行编码为合法字符(因不支持%,中文无法使用 urlencode 处理,请使用其他编码方式)
* @param page 必须是已经发布的小程序页面,例如 "pages/index/index" ,如果不填写这个字段,默认跳主页面
* @param filePath 二维码生成的文件路径,例如: /var/temp
* @return 文件对象
* @throws WxErrorException 异常
*/
File createWxaCodeUnlimit(String scene, String page, String filePath) throws WxErrorException;
/**
* 接口B: 获取小程序码(永久有效、数量暂无限制).
* <pre>
* 通过该接口生成的小程序码,永久有效,数量暂无限制。
* 用户扫描该码进入小程序后,将统一打开首页,开发者需在对应页面根据获取的码中 scene 字段的值,再做处理逻辑。
* 使用如下代码可以获取到二维码中的 scene 字段的值。
* 调试阶段可以使用开发工具的条件编译自定义参数 scene=xxxx 进行模拟,开发工具模拟时的 scene 的参数值需要进行 urlencode
* </pre>
*
* @param scene 最大32个可见字符,只支持数字,大小写英文以及部分特殊字符:!#$&'()*+,/:;=?@-._~,
* 其它字符请自行编码为合法字符(因不支持%,中文无法使用 urlencode 处理,请使用其他编码方式)
* @param page 必须是已经发布的小程序页面,例如 "pages/index/index" ,如果不填写这个字段,默认跳主页面
* @return 文件对象
* @throws WxErrorException 异常
*/
File createWxaCodeUnlimit(String scene, String page) throws WxErrorException;
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopAfterSaleService.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopAfterSaleService.java | package cn.binarywang.wx.miniapp.api;
import cn.binarywang.wx.miniapp.bean.shop.request.*;
import cn.binarywang.wx.miniapp.bean.shop.response.*;
import me.chanjar.weixin.common.error.WxErrorException;
/**
* 小程序交易组件-售后服务
*
* @author boris
* @author liming1019
*/
public interface WxMaShopAfterSaleService {
/**
* 创建售后
*
* @param request
* @return WxMaShopBaseResponse
* @throws WxErrorException
*/
WxMaShopAfterSaleAddResponse add(WxMaShopAfterSaleAddRequest request) throws WxErrorException;
/**
* 获取订单下售后单
*
* @param request
* @return WxMaShopAfterSaleGetResponse
* @throws WxErrorException
*/
WxMaShopAfterSaleGetResponse get(WxMaShopAfterSaleGetRequest request) throws WxErrorException;
/**
* 获取售后单详情(EC版)
*
* @param request
* @return WxMaShopEcAfterSaleGetResponse
* @throws WxErrorException
*/
WxMaShopEcAfterSaleGetResponse get(WxMaShopEcAfterSaleGetRequest request) throws WxErrorException;
/**
* 更新售后
*
* @param request
* @return WxMaShopBaseResponse
* @throws WxErrorException
*/
WxMaShopBaseResponse update(WxMaShopAfterSaleUpdateRequest request) throws WxErrorException;
/**
* 更新售后(EC版)
*
* @param request
* @return WxMaShopBaseResponse
* @throws WxErrorException
*/
WxMaShopBaseResponse update(WxMaShopEcAfterSaleUpdateRequest request) throws WxErrorException;
/**
* 用户取消售后申请
* @param outAfterSaleId 商家自定义订单ID
* @param afterSaleId 与out_aftersale_id二选一
* @param openId 用户openid
* @return
* @throws WxErrorException
*/
WxMaShopBaseResponse cancel(String outAfterSaleId, Long afterSaleId, String openId)
throws WxErrorException;
/**
* 用户上传退货物流
* @param request
* @return
* @throws WxErrorException
*/
WxMaShopBaseResponse uploadReturnInfo(WxMaShopAfterSaleUploadReturnInfoRequest request)
throws WxErrorException;
/**
* 商家同意退款
* @param outAfterSaleId
* @param afterSaleId
* @return
* @throws WxErrorException
*/
WxMaShopBaseResponse acceptRefund(String outAfterSaleId, Long afterSaleId)
throws WxErrorException;
/**
* 商家同意退货
* @param request
* @return
* @throws WxErrorException
*/
WxMaShopBaseResponse acceptReturn(WxMaShopAcceptReturnRequest request)
throws WxErrorException;
/**
* 商家拒绝售后
* @param outAfterSaleId
* @param afterSaleId
* @return
* @throws WxErrorException
*/
WxMaShopBaseResponse reject(String outAfterSaleId, Long afterSaleId)
throws WxErrorException;
/**
* 商家上传退款凭证
* @param request
* @return
* @throws WxErrorException
*/
WxMaShopBaseResponse uploadCertificates(WxMaShopUploadCerficatesRequest request)
throws WxErrorException;
/**
* 商家更新订单售后期
* @param outOrderId
* @param orderId
* @param openid
* @param afterSaleDeadline
* @return
* @throws WxErrorException
*/
WxMaShopBaseResponse updateDeadline(String outOrderId, Long orderId, String openid,
Long afterSaleDeadline) throws WxErrorException;
/**
* 获取售后单详情
* @param request
* @return
* @throws WxErrorException
*/
WxMaShopAfterSaleListResponse list(WxMaShopAfterSaleListRequest request) throws WxErrorException;
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaLiveGoodsService.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaLiveGoodsService.java | package cn.binarywang.wx.miniapp.api;
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveGoodInfo;
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveResult;
import me.chanjar.weixin.common.error.WxErrorException;
import java.util.List;
/**
* <pre>
* 直播间商品相关操作接口
* 文档地址:https://developers.weixin.qq.com/miniprogram/dev/framework/liveplayer/commodity-api.html
* Created by lipengjun on 2020/6/29.
* </pre>
*
* @author <a href="https://github.com/lipengjun92">lipengjun (939961241@qq.com)</a>
*/
public interface WxMaLiveGoodsService {
/**
* 商品添加并提审
* <pre>
* 调用此接口上传并提审需要直播的商品信息,审核通过后商品录入【小程序直播】商品库
* 注意:开发者必须保存【商品ID】与【审核单ID】,如果丢失,则无法调用其他相关接口
* 调用额度:500次/一天
* http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/goods/add?access_token=ACCESS_TOKEN
*
* 文档地址:https://developers.weixin.qq.com/miniprogram/dev/framework/liveplayer/commodity-api.html#1
* </pre>
*
* @param goods 商品
* @return 返回auditId、goodsId
* @throws WxErrorException .
*/
WxMaLiveResult addGoods(WxMaLiveGoodInfo goods) throws WxErrorException;
/**
* 撤回审核
* <pre>
* 调用此接口,可撤回直播商品的提审申请,消耗的提审次数不返还
* 调用额度:500次/一天
* http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/goods/resetaudit?access_token=ACCESS_TOKEN
* <pre>
* @param auditId 审核单ID
* @param goodsId 商品ID
* @return 撤回审核是否成功
* @throws WxErrorException .
*/
boolean resetAudit(Integer auditId, Integer goodsId) throws WxErrorException;
/**
* 重新提交审核
* <pre>
* 调用此接口,可撤回直播商品的提审申请,消耗的提审次数不返还
* 调用额度:500次/一天(与接口'商品添加并提审'共用500次限制)
* http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/goods/audit?access_token=ACCESS_TOKEN
* <pre>
* @param goodsId 商品ID
* @return 审核单ID
* @throws WxErrorException .
*/
String auditGoods(Integer goodsId) throws WxErrorException;
/**
* 删除商品
* <pre>
* 调用此接口,可删除【小程序直播】商品库中的商品,删除后直播间上架的该商品也将被同步删除,不可恢复;
* 调用额度:1000次/一天
* http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/goods/delete?access_token=ACCESS_TOKEN
* <pre>
* @param goodsId 商品ID
* @return 删除商品是否成功
* @throws WxErrorException .
*/
boolean deleteGoods(Integer goodsId) throws WxErrorException;
/**
* 更新商品
* <pre>
* 调用此接口可以更新商品信息,审核通过的商品仅允许更新价格类型与价格,审核中的商品不允许更新,未审核的商品允许更新所有字段, 只传入需要更新的字段。
* 调用额度:1000次/一天
* http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/goods/update?access_token=ACCESS_TOKEN
* </pre>
*
* @param goods 商品
* @return 更新商品是否成功
* @throws WxErrorException .
*/
boolean updateGoods(WxMaLiveGoodInfo goods) throws WxErrorException;
/**
* 获取商品状态
* <pre>
* 调用此接口可获取商品的信息与审核状态
* 调用额度:1000次/一天
* http请求方式:POST https://api.weixin.qq.com/wxa/business/getgoodswarehouse?access_token=ACCESS_TOKEN
* <pre>
* @param goodsIds 商品ID集
* @return 商品状态信息
* @throws WxErrorException .
*/
WxMaLiveResult getGoodsWareHouse(List<Integer> goodsIds) throws WxErrorException;
/**
* 获取商品列表
* <pre>
* 调用此接口可获取商品列表
* 调用额度:10000次/一天
* http请求方式:GET https://api.weixin.qq.com/wxaapi/broadcast/goods/getapproved?access_token=ACCESS_TOKEN
* <pre>
* @param offset 分页条数起点
* @param limit 分页大小,默认30,不超过100
* @param status 商品状态,0:未审核。1:审核中,2:审核通过,3:审核驳回
* @return 商品列表
* @throws WxErrorException .
*/
WxMaLiveResult getApprovedGoods(Integer offset, Integer limit, Integer status) throws WxErrorException;
/**
* 直播挂件设置全局key
* <pre>
* 若已设置此全局key,且添加商品时未指定goodsKey字段,则我们会使用此全局key作为该商品的goodsKey。 须注意的是,若全局key已设定,并添加了未指定goodsKey字段的商品之后,再重新设定不一样的全局key则会导致先前的映射失效。 为了避免映射失效,建议全局key只设定一次。
* 注意:key必须为字符串数组
* 调用额度:500次/一天
* http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/goods/setkey?access_token=
* </pre>
*
* @param goodsKey 全局key
* @return 设置是否成功
* @throws WxErrorException .
*/
boolean setKey(List<String> goodsKey) throws WxErrorException;
/**
* 查看当前设定的全局key
* <pre>
* 查看当前设定的全局key。
* 调用额度:500次/一天
* http请求方式:GET https://api.weixin.qq.com/wxaapi/broadcast/goods/getkey?access_token=
* </pre>
*
* @return 全局key
* @throws WxErrorException .
*/
List<String> getKey() throws WxErrorException;
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaService.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaService.java | package cn.binarywang.wx.miniapp.api;
import cn.binarywang.wx.miniapp.bean.WxMaApiResponse;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import cn.binarywang.wx.miniapp.config.WxMaConfig;
import cn.binarywang.wx.miniapp.executor.ApiSignaturePostRequestExecutor;
import com.google.gson.JsonObject;
import java.util.Map;
import java.util.function.Function;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.service.WxImgProcService;
import me.chanjar.weixin.common.service.WxOcrService;
import me.chanjar.weixin.common.service.WxService;
import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
import me.chanjar.weixin.common.util.http.RequestExecutor;
import me.chanjar.weixin.common.util.http.RequestHttp;
/**
* 微信小程序主服务接口,定义了所有小程序相关的核心操作方法。
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
public interface WxMaService extends WxService {
/** 获取access_token. */
String GET_ACCESS_TOKEN_URL =
"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s";
String GET_STABLE_ACCESS_TOKEN = "https://api.weixin.qq.com/cgi-bin/stable_token";
/** The constant JSCODE_TO_SESSION_URL. */
String JSCODE_TO_SESSION_URL = "https://api.weixin.qq.com/sns/jscode2session";
/** getPaidUnionId */
String GET_PAID_UNION_ID_URL = "https://api.weixin.qq.com/wxa/getpaidunionid";
/** 导入抽样数据 */
String SET_DYNAMIC_DATA_URL = "https://api.weixin.qq.com/wxa/setdynamicdata";
/**
* 获取登录后的 session 信息。
*
* @param jsCode 登录时获取的 code
* @return 登录 session 结果对象
* @throws WxErrorException 调用微信接口失败时抛出
*/
WxMaJscode2SessionResult jsCode2SessionInfo(String jsCode) throws WxErrorException;
/**
* 导入抽样数据到微信后台,用于流量分配。
* 第三方通过调用微信API,将数据写入到setdynamicdata这个API。每个Post数据包不超过5K,若数据过多可开多进(线)程并发导入数据(例如:数据量为十万量级可以开50个线程并行导数据)。
* 文档地址:https://wsad.weixin.qq.com/wsad/zh_CN/htmledition/widget-docs-v3/html/custom/quickstart/implement/import/index.html
* http请求方式:POST http(s)://api.weixin.qq.com/wxa/setdynamicdata?access_token=ACCESS_TOKEN
*
* @param lifespan 数据有效时间(秒),如 86400 表示一天
* @param type 数据所属服务类目标识
* @param scene 场景值,1 代表用于搜索的数据
* @param data 推送到微信后台的数据列表(字符串类型)
* @throws WxErrorException 调用微信接口失败时抛出
*/
void setDynamicData(int lifespan, String type, int scene, String data) throws WxErrorException;
/**
* 校验消息是否来自微信服务器。
* 详情请见: http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421135319&token=&lang=zh_CN
*
* @param timestamp 时间戳
* @param nonce 随机数
* @param signature 签名字符串
* @return 校验通过返回 true,否则返回 false
*/
boolean checkSignature(String timestamp, String nonce, String signature);
/**
* 获取 access_token,不强制刷新。
*
* @return access_token 字符串
* @throws WxErrorException 调用微信接口失败时抛出
* @see #getAccessToken(boolean)
*/
String getAccessToken() throws WxErrorException;
/**
* 获取 access_token,本方法线程安全。多线程同时刷新时只刷新一次,避免超出调用次数上限。
* 一般无需主动调用,所有接口会自动处理 token 过期。
* 详情见:http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140183&token=&lang=zh_CN
*
* @param forceRefresh 是否强制刷新
* @return access_token 字符串
* @throws WxErrorException 调用微信接口失败时抛出
*/
String getAccessToken(boolean forceRefresh) throws WxErrorException;
/**
* 用户支付完成后,获取该用户的 UnionId,无需用户授权。本接口支持第三方平台代理查询。
* 注意:调用前需要用户完成支付,且在支付后的五分钟内有效。
* 请求地址: GET https://api.weixin.qq.com/wxa/getpaidunionid?access_token=ACCESS_TOKEN&openid=OPENID
* 文档:https://developers.weixin.qq.com/miniprogram/dev/api/getPaidUnionId.html
*
* @param openid 支付用户唯一标识(必填)
* @param transactionId 微信支付订单号(可选)
* @param mchId 微信支付分配的商户号,与商户订单号配合使用(可选)
* @param outTradeNo 微信支付商户订单号,与商户号配合使用(可选)
* @return 用户的 UnionId
* @throws WxErrorException 调用微信接口失败时抛出
*/
String getPaidUnionId(String openid, String transactionId, String mchId, String outTradeNo)
throws WxErrorException;
/**
* 执行自定义的微信API请求。
* <br>
* Service没有实现某个API的时候,可以用这个方法,比{@link #get}和{@link #post}方法更灵活,可以自己构造RequestExecutor用来处理不同的参数和不同的返回类型。
* 可以参考 {@link MediaUploadRequestExecutor} 的实现方法。
*
* @param <T> 返回的数据类型
* @param <E> 请求参数的数据类型
* @param executor 执行器对象
* @param uri 接口请求地址
* @param data 请求参数或数据
* @return 微信接口返回的数据对象
* @throws WxErrorException 微信接口调用异常
*/
<T, E> T execute(RequestExecutor<T, E> executor, String uri, E data) throws WxErrorException;
/**
* 执行带有签名的微信API请求。
*
* @param executor 签名请求执行器
* @param uri 接口请求地址
* @param headers 请求头信息
* @param data 请求数据
* @return 微信接口响应对象
* @throws WxErrorException 微信接口调用异常
*/
WxMaApiResponse execute(
ApiSignaturePostRequestExecutor<?, ?> executor,
String uri,
Map<String, String> headers,
String data)
throws WxErrorException;
/**
* 设置微信系统繁忙时的重试等待时间(毫秒)。
*
* @param retrySleepMillis 重试等待的毫秒数,默认1000ms
*/
void setRetrySleepMillis(int retrySleepMillis);
/**
* 设置微信系统繁忙时的最大重试次数。
*
* @param maxRetryTimes 最大重试次数,默认5次
*/
void setMaxRetryTimes(int maxRetryTimes);
/**
* 获取当前小程序的配置信息对象。
*
* @return 当前小程序的WxMaConfig配置对象
*/
WxMaConfig getWxMaConfig();
/**
* 注入小程序配置信息。
*
* @param maConfig 小程序配置信息对象
*/
void setWxMaConfig(WxMaConfig maConfig);
/**
* 动态添加新的小程序配置信息。
*
* @param miniappId 小程序唯一标识
* @param configStorage 新的小程序配置信息
*/
void addConfig(String miniappId, WxMaConfig configStorage);
/**
* 动态移除指定小程序的配置信息。
*
* @param miniappId 小程序唯一标识
*/
void removeConfig(String miniappId);
/**
* 批量注入多个小程序配置信息。
*
* @param configs 小程序配置Map,key为小程序标识
*/
void setMultiConfigs(Map<String, WxMaConfig> configs);
/**
* 批量注入多个小程序配置信息,并指定默认小程序。
*
* @param configs 小程序配置Map,key为小程序标识
* @param defaultMiniappId 默认小程序标识
*/
void setMultiConfigs(Map<String, WxMaConfig> configs, String defaultMiniappId);
/**
* 切换到指定公众号。
*
* @param mpId 公众号标识
* @return 切换是否成功,true为成功,false为失败
*/
boolean switchover(String mpId);
/**
* 切换到指定小程序。
*
* @param miniAppId 小程序标识
* @return 切换成功则返回当前对象,方便链式调用,否则抛出异常
*/
WxMaService switchoverTo(String miniAppId);
/**
* 切换到指定小程序,并在配置不存在时通过函数获取配置。
*
* @param miniAppId 小程序标识
* @param func 获取配置的函数
* @return 切换成功则返回当前对象,方便链式调用,否则抛出异常
*/
WxMaService switchoverTo(String miniAppId, Function<String, WxMaConfig> func);
/**
* 获取消息(客服消息和模板消息)发送服务对象。
*
* @return 消息服务对象WxMaMsgService
*/
WxMaMsgService getMsgService();
/**
* 获取素材相关服务对象。
*
* @return 素材服务对象WxMaMediaService
*/
WxMaMediaService getMediaService();
/**
* 获取用户相关服务对象。
*
* @return 用户服务对象WxMaUserService
*/
WxMaUserService getUserService();
/**
* 获取二维码相关服务对象。
*
* @return 二维码服务对象WxMaQrcodeService
*/
WxMaQrcodeService getQrcodeService();
/**
* 获取小程序scheme码服务对象。
*
* @return scheme码服务对象WxMaSchemeService
*/
WxMaSchemeService getWxMaSchemeService();
/**
* 获取订阅消息配置相关服务对象。
*
* @return 订阅消息服务对象WxMaSubscribeService
*/
WxMaSubscribeService getSubscribeService();
/**
* 获取数据分析相关服务对象。
*
* @return 数据分析服务对象WxMaAnalysisService
*/
WxMaAnalysisService getAnalysisService();
/**
* 获取代码操作相关服务对象。
*
* @return 代码服务对象WxMaCodeService
*/
WxMaCodeService getCodeService();
/**
* 获取小程序 - 微信客服。
*
* @return 微信客服服务对象WxMaCustomserviceWorkService
*/
WxMaCustomserviceWorkService getCustomserviceWorkService();
/**
* 获取小程序客服管理服务。
*
* @return 客服管理服务对象WxMaKefuService
*/
WxMaKefuService getKefuService();
/**
* 获取jsapi操作相关服务对象。
*
* @return jsapi服务对象WxMaJsapiService
*/
WxMaJsapiService getJsapiService();
/**
* 获取小程序服务器地址、成员管理相关服务对象。
*
* @return 设置服务对象WxMaSettingService
*/
WxMaSettingService getSettingService();
/**
* 获取分享相关服务对象。
*
* @return 分享服务对象WxMaShareService
*/
WxMaShareService getShareService();
/**
* 获取微信运动相关服务对象。
*
* @return 微信运动服务对象WxMaRunService
*/
WxMaRunService getRunService();
/**
* 获取小程序安全相关服务对象。
*
* @return 安全服务对象WxMaSecurityService
*/
WxMaSecurityService getSecurityService();
/**
* 获取插件相关服务对象。
*
* @return 插件服务对象WxMaPluginService
*/
WxMaPluginService getPluginService();
/**
* 初始化http请求对象。
*/
void initHttp();
/**
* 获取http请求相关信息。
*
* @return http请求对象RequestHttp
*/
RequestHttp<?, ?> getRequestHttp();
/**
* 获取物流助手接口服务对象。
*
* @return 物流助手服务对象WxMaExpressService
*/
WxMaExpressService getExpressService();
/**
* 获取云开发接口服务对象。
*
* @return 云开发服务对象WxMaCloudService
*/
WxMaCloudService getCloudService();
/**
* 获取服务端网络接口服务对象。
*
* @return 网络服务对象WxMaInternetService
*/
WxMaInternetService getInternetService();
/**
* 获取直播接口服务对象。
*
* @return 直播服务对象WxMaLiveService
*/
WxMaLiveService getLiveService();
/**
* 获取直播间商品服务对象。
*
* @return 直播商品服务对象WxMaLiveGoodsService
*/
WxMaLiveGoodsService getLiveGoodsService();
/**
* 获取直播成员管理接口服务对象。
*
* @return 直播成员服务对象WxMaLiveMemberService
*/
WxMaLiveMemberService getLiveMemberService();
/**
* 获取OCR实现接口服务对象。
*
* @return OCR服务对象WxOcrService
*/
WxOcrService getOcrService();
/**
* 获取图像处理接口服务对象。
*
* @return 图像处理服务对象WxImgProcService
*/
WxImgProcService getImgProcService();
/**
* 获取小程序交易组件-售后服务接口服务对象。
*
* @return 售后服务对象WxMaShopAfterSaleService
*/
WxMaShopAfterSaleService getShopAfterSaleService();
/**
* 获取小程序交易组件-物流服务接口服务对象。
*
* @return 物流服务对象WxMaShopDeliveryService
*/
WxMaShopDeliveryService getShopDeliveryService();
/**
* 获取小程序交易组件-订单服务接口服务对象。
*
* @return 订单服务对象WxMaShopOrderService
*/
WxMaShopOrderService getShopOrderService();
/**
* 获取小程序交易组件-spu商品服务接口服务对象。
*
* @return spu商品服务对象WxMaShopSpuService
*/
WxMaShopSpuService getShopSpuService();
/**
* 获取小程序交易组件-接入申请接口服务对象。
*
* @return 接入申请服务对象WxMaShopRegisterService
*/
WxMaShopRegisterService getShopRegisterService();
/**
* 获取小程序交易组件-商户入驻接口服务对象。
*
* @return 商户入驻服务对象WxMaShopAccountService
*/
WxMaShopAccountService getShopAccountService();
/**
* 获取小程序交易组件-类目相关接口服务对象。
*
* @return 类目服务对象WxMaShopCatService
*/
WxMaShopCatService getShopCatService();
/**
* 获取小程序交易组件-上传图片接口服务对象。
*
* @return 图片服务对象WxMaShopImgService
*/
WxMaShopImgService getShopImgService();
/**
* 获取小程序交易组件-审核相关接口服务对象。
*
* @return 审核服务对象WxMaShopAuditService
*/
WxMaShopAuditService getShopAuditService();
/**
* 获取小程序Link服务接口服务对象。
*
* @return Link服务对象WxMaLinkService
*/
WxMaLinkService getLinkService();
/**
* 获取电子发票报销方服务接口服务对象。
*
* @return 电子发票报销方服务对象WxMaReimburseInvoiceService
*/
WxMaReimburseInvoiceService getReimburseInvoiceService();
/**
* 获取设备订阅消息相关接口服务对象。
*
* @return 设备订阅消息服务对象WxMaDeviceSubscribeService
*/
WxMaDeviceSubscribeService getDeviceSubscribeService();
/**
* 获取小程序广告接入相关接口服务对象。
*
* @return 广告服务对象WxMaMarketingService
*/
WxMaMarketingService getMarketingService();
/**
* 获取微信小程序即时配送服务接口服务对象。
*
* @return 即时配送服务对象WxMaImmediateDeliveryService
*/
WxMaImmediateDeliveryService getWxMaImmediateDeliveryService();
/**
* 获取小程序分享人接口服务对象。
*
* @return 分享人服务对象WxMaShopSharerService
*/
WxMaShopSharerService getShopSharerService();
/**
* 获取标准交易组件接口服务对象。
*
* @return 标准交易组件服务对象WxMaProductService
*/
WxMaProductService getProductService();
/**
* 获取小商店-标准交易组件-订单服务对象。
*
* @return 订单服务对象WxMaProductOrderService
*/
WxMaProductOrderService getProductOrderService();
/**
* 获取小商店-标准交易组件-优惠券服务对象。
*
* @return 优惠券服务对象WxMaShopCouponService
*/
WxMaShopCouponService getWxMaShopCouponService();
/**
* 获取小程序支付管理-订单支付服务对象。
*
* @return 订单支付服务对象WxMaShopPayService
*/
WxMaShopPayService getWxMaShopPayService();
/**
* 获取小程序发货信息管理服务对象。
*
* @return 发货信息管理服务对象WxMaOrderShippingService
*/
WxMaOrderShippingService getWxMaOrderShippingService();
/**
* 获取小程序订单管理服务对象。
*
* @return 订单管理服务对象WxMaOrderManagementService
*/
WxMaOrderManagementService getWxMaOrderManagementService();
/**
* 获取小程序openApi管理服务对象。
*
* @return openApi管理服务对象WxMaOpenApiService
*/
WxMaOpenApiService getWxMaOpenApiService();
/**
* 获取小程序短剧管理服务对象。
*
* @return 短剧管理服务对象WxMaVodService
*/
WxMaVodService getWxMaVodService();
/**
* 获取小程序虚拟支付服务对象。
*
* @return 虚拟支付服务对象WxMaXPayService
*/
WxMaXPayService getWxMaXPayService();
/**
* 获取小程序物流退货服务对象。
*
* @return 物流退货服务对象WxMaExpressDeliveryReturnService
*/
WxMaExpressDeliveryReturnService getWxMaExpressDeliveryReturnService();
/**
* 获取小程序推广员服务对象。
*
* @return 推广员服务对象WxMaPromotionService
*/
WxMaPromotionService getWxMaPromotionService();
/**
* 以签名方式POST数据到指定URL。
*
* @param url 请求地址
* @param obj 请求对象
* @return 微信接口响应字符串
* @throws WxErrorException 微信接口调用异常
*/
String postWithSignature(String url, Object obj) throws WxErrorException;
/**
* 以签名方式POST数据到指定URL。
*
* @param url 请求地址
* @param jsonObject 请求的Json对象
* @return 微信接口响应字符串
* @throws WxErrorException 微信接口调用异常
*/
String postWithSignature(String url, JsonObject jsonObject) throws WxErrorException;
/**
* 获取微信物流服务--同城配送服务对象。
* <br>
* 文档:https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/industry/express/business/intracity_service.html
*
* @return 同城配送服务对象WxMaIntracityService
*/
WxMaIntracityService getIntracityService();
/**
* 获取交易投诉服务对象。
* <br>
* 文档:https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/guarantee/complaint.html
*
* @return 交易投诉服务对象WxMaComplaintService
*/
WxMaComplaintService getComplaintService();
/**
* 获取用工关系服务对象。
* <br>
* 文档:https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/laboruse/intro.html
*
* @return 用工关系服务对象WxMaEmployeeRelationService
*/
WxMaEmployeeRelationService getEmployeeRelationService();
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopPayService.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopPayService.java | package cn.binarywang.wx.miniapp.api;
import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopPayCreateOrderRequest;
import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopPayOrderRefundRequest;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopBaseResponse;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopPayCreateOrderResponse;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopPayGetOrderResponse;
import me.chanjar.weixin.common.error.WxErrorException;
/**
* 小程序支付管理订单相关接口
*
* @author liming1019
*/
public interface WxMaShopPayService {
/**
* 创建订单
* 文档地址:<a href="https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/ministore/wxafunds/API/order/create_order.html">文档地址</a>
*
* @param request 创建订单参数
* @return 创建订单结果
* @throws WxErrorException .
*/
WxMaShopPayCreateOrderResponse createOrder(WxMaShopPayCreateOrderRequest request) throws WxErrorException;
/**
* 查询订单详情
* 文档地址:<a href="https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/ministore/wxafunds/API/order/get_order_detail.html">文档地址</a>
*
* @param trade_no
* @return
* @throws WxErrorException
*/
WxMaShopPayGetOrderResponse getOrder(String trade_no) throws WxErrorException;
/**
* 订单退款
* 文档地址:<a href="https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/ministore/wxafunds/API/order/refunds_order.html">文档地址</a>
*
* @param request
* @return
* @throws WxErrorException
*/
WxMaShopBaseResponse refundOrder(WxMaShopPayOrderRefundRequest request) throws WxErrorException;
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaIntracityService.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaIntracityService.java | package cn.binarywang.wx.miniapp.api;
import cn.binarywang.wx.miniapp.bean.intractiy.*;
import java.util.List;
import me.chanjar.weixin.common.error.WxErrorException;
/**
* 微信小程序 物流服务 同城配送服务API <br>
* *不是*即时配送接口,两个相近,容易混淆<br>
* 微信相关接口 <br>
* https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/industry/express/business/intracity_service.html
*/
public interface WxMaIntracityService {
/** 申请开通门店权限 */
void apply() throws WxErrorException;
/** 创建门店 */
String createStore(WxMaStore store) throws WxErrorException;
/**
* 更新门店;只更新store中不为null的部分 wxStoreId和outStoreId至少要有一个不为null,根据这2个来更新。 仅支持更新 storeName orderPattern
* serviceTransPrefer addressInfo几个属性
*/
void updateStore(WxMaStore store) throws WxErrorException;
/** 查询门店(列出所有门店) */
List<WxMaStore> listAllStores() throws WxErrorException;
/** 根据wx_store_id查询门店 */
WxMaStore queryStoreByWxStoreId(String wxStoreId) throws WxErrorException;
/** 根据 out_store_id 查询门店 */
List<WxMaStore> queryStoreByOutStoreId(String outStoreId) throws WxErrorException;
/** 门店运费充值,返回充值URL */
String storeCharge(WxMaStoreChargeRequest request) throws WxErrorException;
/** 门店运费退款,返回退款金额 */
int storeRefund(WxMaStoreRefundRequest request) throws WxErrorException;
/** 门店运费流水查询 */
WxMaStoreFlowResponse<? extends WxMaStoreFlowResponse.BasicFlowRecord> queryFlow(
WxMaQueryFlowRequest request) throws WxErrorException;
/** 查询门店余额 */
WxMaStoreBalance balanceQuery(String wxStoreId, String serviceTransId, PayMode payMode)
throws WxErrorException;
/**
* 设置扣费主体 <br>
* 接口调用成功后,小程序的管理员会收到模板消息,点击模板消息确认更改门店扣费主体后,修改生效。
*/
void setPayMode(PayMode payMode) throws WxErrorException;
/** 查询扣费主体 */
WxMaGetPayModeResponse getPayMode() throws WxErrorException;
/** 查询运费 */
WxMaPreAddOrderResponse preAddOrder(WxMaPreAddOrderRequest request) throws WxErrorException;
/** 创建配送单 */
WxMaAddOrderResponse addOrder(WxMaAddOrderRequest order) throws WxErrorException;
/** 查询配送单 根据wxOrderId */
WxMaOrder queryOrderByWxOrderId(String wxOrderId) throws WxErrorException;
/** 依据商户订单号 查询配送单 */
WxMaOrder queryOrderByStoreOrderId(String wxStoreId, String storeOrderId) throws WxErrorException;
/** 依据微信订单号 查询配送单 */
WxMaCancelOrderResponse cancelOrderByWxOrderId(
String wxOrderId, int cancelReasonId, String cancelReason) throws WxErrorException;
/** 依据商户订单号 查询配送单 */
WxMaCancelOrderResponse cancelOrderByStoreOrderId(
String wxStoreId, String storeOrderId, int cancelReasonId, String cancelReason)
throws WxErrorException;
/**
* 查询支持同城配送的城市
*
* @param serviceTransId 运力ID,传NULL则返回所有
*/
List<WxMaTransCity> getCity(String serviceTransId) throws WxErrorException;
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaSecurityServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaSecurityServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaSecurityService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaMediaAsyncCheckResult;
import cn.binarywang.wx.miniapp.bean.safety.request.WxMaUserSafetyRiskRankRequest;
import cn.binarywang.wx.miniapp.bean.safety.response.WxMaUserSafetyRiskRankResponse;
import cn.binarywang.wx.miniapp.bean.security.WxMaMediaSecCheckCheckRequest;
import cn.binarywang.wx.miniapp.bean.security.WxMaMsgSecCheckCheckRequest;
import cn.binarywang.wx.miniapp.bean.security.WxMaMsgSecCheckCheckResponse;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
import me.chanjar.weixin.common.util.json.GsonParser;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.SecCheck.*;
import static me.chanjar.weixin.common.api.WxConsts.ERR_CODE;
/**
* <pre>
* 小程序安全接口
* Created by Binary Wang on 2018/11/24.
* </pre>
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
@RequiredArgsConstructor
public class WxMaSecurityServiceImpl implements WxMaSecurityService {
private final WxMaService service;
@Override
public boolean checkImage(File file) throws WxErrorException {
WxMediaUploadResult result = this.service.execute(MediaUploadRequestExecutor
.create(this.service.getRequestHttp()), IMG_SEC_CHECK_URL, file);
return result != null;
}
@Override
public boolean checkImage(String fileUrl) throws WxErrorException {
File file = new File(FileUtils.getTempDirectory(), System.currentTimeMillis() + ".tmp");
try {
URL url = new URL(fileUrl);
FileUtils.copyURLToFile(url, file);
} catch (IOException e) {
throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("文件地址读取异常").build(), e);
}
return this.checkImage(file);
}
@Override
public boolean checkMessage(String msgString) throws WxErrorException {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("content", msgString);
this.service.post(MSG_SEC_CHECK_URL, jsonObject.toString());
return true;
}
@Override
public WxMaMsgSecCheckCheckResponse checkMessage(WxMaMsgSecCheckCheckRequest msgRequest) throws WxErrorException {
String response = this.service.post(MSG_SEC_CHECK_URL, msgRequest);
parseErrorResponse(response);
return WxMaGsonBuilder.create().fromJson(response, WxMaMsgSecCheckCheckResponse.class);
}
@Override
public WxMaMediaAsyncCheckResult mediaCheckAsync(String mediaUrl, int mediaType)
throws WxErrorException {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("media_url", mediaUrl);
jsonObject.addProperty("media_type", mediaType);
return WxMaMediaAsyncCheckResult
.fromJson(this.service.post(MEDIA_CHECK_ASYNC_URL, jsonObject.toString()));
}
@Override
public WxMaMediaAsyncCheckResult mediaCheckAsync(WxMaMediaSecCheckCheckRequest request) throws WxErrorException {
String response = this.service.post(MEDIA_CHECK_ASYNC_URL, request);
parseErrorResponse(response);
return WxMaGsonBuilder.create().fromJson(response,WxMaMediaAsyncCheckResult.class);
}
@Override
public WxMaUserSafetyRiskRankResponse getUserRiskRank(WxMaUserSafetyRiskRankRequest wxMaUserSafetyRiskRankRequest) throws WxErrorException {
String responseContent = this.service.post(GET_USER_RISK_RANK, wxMaUserSafetyRiskRankRequest.toJson());
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaUserSafetyRiskRankResponse.fromJson(responseContent);
}
private void parseErrorResponse(String response) throws WxErrorException {
JsonObject jsonObject = GsonParser.parse(response);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(response, WxType.MiniApp));
}
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import lombok.extern.slf4j.Slf4j;
/**
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
@Slf4j
public class WxMaServiceImpl extends WxMaServiceHttpClientImpl {
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaReimburseInvoiceServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaReimburseInvoiceServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaReimburseInvoiceService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.invoice.reimburse.*;
import lombok.AllArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import java.util.List;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Invoice.*;
/**
* 电子发票报销方相关接口实现
* 接口文档: https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/E_Invoice/Reimburser_API_List.html
* @author <a href="https://github.com/mr-xiaoyu">xiaoyu</a>
* @since 2021-06-10
*/
@AllArgsConstructor
public class WxMaReimburseInvoiceServiceImpl implements WxMaReimburseInvoiceService {
private final WxMaService wxMaService;
@Override
public InvoiceInfoResponse getInvoiceInfo(InvoiceInfoRequest request) throws WxErrorException {
return InvoiceInfoResponse.fromJson(this.wxMaService.post(GET_INVOICE_INFO,request.toJson()));
}
@Override
public List<InvoiceInfoResponse> getInvoiceBatch(InvoiceBatchRequest request) throws WxErrorException {
return InvoiceInfoResponse.toList(this.wxMaService.post(GET_INVOICE_BATCH,request.toJson()));
}
@Override
public void updateInvoiceStatus(UpdateInvoiceStatusRequest request) throws WxErrorException {
this.wxMaService.post(UPDATE_INVOICE_STATUS,request.toJson());
}
@Override
public void updateStatusBatch(UpdateStatusBatchRequest request) throws WxErrorException {
this.wxMaService.post(UPDATE_STATUS_BATCH,request.toJson());
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaServiceJoddHttpImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaServiceJoddHttpImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaStableAccessTokenRequest;
import cn.binarywang.wx.miniapp.config.WxMaConfig;
import jodd.http.HttpConnectionProvider;
import jodd.http.HttpRequest;
import jodd.http.ProxyInfo;
import jodd.http.net.SocketHttpConnectionProvider;
import jodd.net.MimeTypes;
import me.chanjar.weixin.common.util.http.HttpClientType;
import org.apache.commons.lang3.StringUtils;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
/**
* jodd-http方式实现.
*
* @author someone
*/
public class WxMaServiceJoddHttpImpl extends BaseWxMaServiceImpl<HttpConnectionProvider, ProxyInfo> {
private HttpConnectionProvider httpClient;
private ProxyInfo httpProxy;
@Override
public void initHttp() {
WxMaConfig configStorage = this.getWxMaConfig();
if (configStorage.getHttpProxyHost() != null && configStorage.getHttpProxyPort() > 0) {
this.httpProxy = new ProxyInfo(ProxyInfo.ProxyType.HTTP, configStorage.getHttpProxyHost(), configStorage.getHttpProxyPort(), configStorage.getHttpProxyUsername(), configStorage.getHttpProxyPassword());
}
this.httpClient = new SocketHttpConnectionProvider();
}
@Override
public HttpConnectionProvider getRequestHttpClient() {
return httpClient;
}
@Override
public ProxyInfo getRequestHttpProxy() {
return httpProxy;
}
@Override
public HttpClientType getRequestType() {
return HttpClientType.JODD_HTTP;
}
@Override
protected String doGetAccessTokenRequest() throws IOException {
String url = StringUtils.isNotEmpty(this.getWxMaConfig().getAccessTokenUrl()) ?
this.getWxMaConfig().getAccessTokenUrl() :
WxMaService.GET_ACCESS_TOKEN_URL.replace(
WxMaConfig.DEFAULT_API_HOST_URL, this.getWxMaConfig().getEffectiveApiHostUrl());
url = String.format(url, this.getWxMaConfig().getAppid(), this.getWxMaConfig().getSecret());
HttpRequest request = HttpRequest.get(url);
if (this.getRequestHttpProxy() != null) {
SocketHttpConnectionProvider provider = new SocketHttpConnectionProvider();
provider.useProxy(getRequestHttpProxy());
request.withConnectionProvider(provider);
}
return request.send().bodyText();
}
@Override
protected String doGetStableAccessTokenRequest(boolean forceRefresh) throws IOException {
String url = StringUtils.isNotEmpty(this.getWxMaConfig().getAccessTokenUrl()) ?
this.getWxMaConfig().getAccessTokenUrl() :
GET_STABLE_ACCESS_TOKEN.replace(
WxMaConfig.DEFAULT_API_HOST_URL, this.getWxMaConfig().getEffectiveApiHostUrl());
WxMaStableAccessTokenRequest wxMaAccessTokenRequest = new WxMaStableAccessTokenRequest();
wxMaAccessTokenRequest.setAppid(this.getWxMaConfig().getAppid());
wxMaAccessTokenRequest.setSecret(this.getWxMaConfig().getSecret());
wxMaAccessTokenRequest.setGrantType("client_credential");
wxMaAccessTokenRequest.setForceRefresh(forceRefresh);
HttpRequest request = HttpRequest.post(url)
.contentType(MimeTypes.MIME_APPLICATION_JSON, StandardCharsets.UTF_8.name())
.body(wxMaAccessTokenRequest.toJson());
if (this.getRequestHttpProxy() != null) {
SocketHttpConnectionProvider provider = new SocketHttpConnectionProvider();
provider.useProxy(getRequestHttpProxy());
request.withConnectionProvider(provider);
}
return request.send().bodyText();
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaImmediateDeliveryServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaImmediateDeliveryServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaImmediateDeliveryService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaBaseResponse;
import cn.binarywang.wx.miniapp.bean.delivery.*;
import cn.binarywang.wx.miniapp.bean.delivery.base.WxMaDeliveryBaseResponse;
import cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.InstantDelivery;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import static me.chanjar.weixin.common.api.WxConsts.ERR_CODE;
/**
* 微信小程序即时配送服务.
* <pre>
* 文档地址:https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/industry/immediate-delivery/overview.html
* </pre>
*
* @author Luo
* @version 1.0
* created on 2021-10-13 16:40
*/
@RequiredArgsConstructor
public class WxMaImmediateDeliveryServiceImpl implements WxMaImmediateDeliveryService {
/**
* 顺丰同城响应码.
*/
public static final String SF_ERR_CODE = "resultcode";
/**
* 顺丰同城响应说明.
*/
public static final String SF_ERR_MSG = "resultmsg";
/**
* 成功响应状态码.
*/
public static final int SUCCESS_CODE = 0;
private final WxMaService wxMaService;
/**
* 拉取已绑定账号.
* <pre>
* 文档地址:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/immediate-delivery/by-business/immediateDelivery.getBindAccount.html
* </pre>
*
* @return 响应
* @throws WxErrorException 异常
*/
@Override
public BindAccountResponse getBindAccount() throws WxErrorException {
return this.parse(this.wxMaService.post(InstantDelivery.GET_BIND_ACCOUNT, "{}"),
BindAccountResponse.class);
}
/**
* 下配送单接口.
* <pre>
* 文档地址:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/immediate-delivery/by-business/immediateDelivery.addOrder.html
* </pre>
*
* @param request request
* @return 响应
* @throws WxErrorException 异常
*/
@Override
public AddOrderResponse addOrder(final AddOrderRequest request) throws WxErrorException {
request.getDeliverySign();
return this.parse(this.wxMaService.post(InstantDelivery.PlaceAnOrder.ADD_ORDER, request),
AddOrderResponse.class);
}
/**
* 拉取配送单信息.
* <pre>
* 商家可使用本接口查询某一配送单的配送状态,便于商家掌握配送情况。
* 文档地址:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/immediate-delivery/by-business/immediateDelivery.getOrder.html
* </pre>
*
* @param request request
* @return 响应
* @throws WxErrorException 异常
*/
@Override
public GetOrderResponse getOrder(final GetOrderRequest request) throws WxErrorException {
request.getDeliverySign();
return this.parse(this.wxMaService.post(InstantDelivery.GET_ORDER, request),
GetOrderResponse.class);
}
/**
* 取消配送单接口.
* <pre>
* 文档地址:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/immediate-delivery/by-business/immediateDelivery.cancelOrder.html
* </pre>
*
* @param request request
* @return 响应
* @throws WxErrorException 异常
*/
@Override
public CancelOrderResponse cancelOrder(final CancelOrderRequest request) throws WxErrorException {
request.getDeliverySign();
return this.parse(this.wxMaService.post(InstantDelivery.Cancel.CANCEL_ORDER, request),
CancelOrderResponse.class);
}
/**
* 异常件退回商家商家确认收货接口.
* <pre>
* 文档地址:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/immediate-delivery/by-business/immediateDelivery.abnormalConfirm.html
* </pre>
*
* @param request request
* @return 响应
* @throws WxErrorException 异常
*/
@Override
public AbnormalConfirmResponse abnormalConfirm(final AbnormalConfirmRequest request) throws WxErrorException {
request.getDeliverySign();
return this.parse(this.wxMaService.post(InstantDelivery.Cancel.ABNORMAL_CONFIRM, request),
AbnormalConfirmResponse.class);
}
/**
* 模拟配送公司更新配送单状态, 该接口只用于沙盒环境,即订单并没有真实流转到运力方.
* <pre>
* 文档地址:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/immediate-delivery/by-business/immediateDelivery.mockUpdateOrder.html
* </pre>
*
* @param request request
* @return 响应
* @throws WxErrorException 异常
*/
@Override
public MockUpdateOrderResponse mockUpdateOrder(final MockUpdateOrderRequest request) throws WxErrorException {
return this.parse(this.wxMaService.post(InstantDelivery.MOCK_UPDATE_ORDER, request),
MockUpdateOrderResponse.class);
}
@Override
public TraceWaybillResponse traceWaybill(
TraceWaybillRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(InstantDelivery.TRACE_WAYBILL_URL, request);
TraceWaybillResponse response = TraceWaybillResponse.fromJson(responseContent);
if (response.getErrcode() == -1) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return response;
}
@Override
public QueryWaybillTraceResponse queryWaybillTrace(
QueryWaybillTraceRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(InstantDelivery.QUERY_WAYBILL_TRACE_URL, request);
QueryWaybillTraceResponse response = QueryWaybillTraceResponse.fromJson(responseContent);
if (response.getErrcode() == -1) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return response;
}
@Override
public FollowWaybillResponse followWaybill(
FollowWaybillRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(InstantDelivery.FOLLOW_WAYBILL_URL, request);
FollowWaybillResponse response = FollowWaybillResponse.fromJson(responseContent);
if (response.getErrcode() == -1) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return response;
}
@Override
public QueryFollowTraceResponse queryFollowTrace(
QueryFollowTraceRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(InstantDelivery.QUERY_FOLLOW_TRACE_URL, request);
QueryFollowTraceResponse response = QueryFollowTraceResponse.fromJson(responseContent);
if (response.getErrcode() == -1) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return response;
}
@Override
public GetDeliveryListResponse getDeliveryList() throws WxErrorException {
String responseContent = this.wxMaService.post(InstantDelivery.GET_DELIVERY_LIST_URL,"{}");
GetDeliveryListResponse response = GetDeliveryListResponse.fromJson(responseContent);
if (response.getErrcode() == -1) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return response;
}
@Override
public WxMaBaseResponse updateWaybillGoods(UpdateWaybillGoodsRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(InstantDelivery.UPDATE_WAYBILL_GOODS_URL,request);
WxMaBaseResponse response = WxMaGsonBuilder.create().fromJson(responseContent, WxMaBaseResponse.class);
if (response.getErrcode() == -1) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return response;
}
/**
* 解析响应.
*
* @param responseContent 响应内容
* @param valueType 类型
* @param <T> 类型
* @return 结果
* @throws WxErrorException 异常
*/
private <T extends WxMaDeliveryBaseResponse> T parse(final String responseContent, final Class<T> valueType) throws WxErrorException {
if (StringUtils.isBlank(responseContent)) {
throw new RuntimeException("the responseContent cannot be empty");
}
// 解析成Json对象
JsonObject jsonObject = GsonParser.parse(responseContent);
// 是否为微信错误响应 当 errcode==0 或者 不存在 还需要看 运力方 resultcode 状态码
JsonElement element = jsonObject.get(ERR_CODE);
// 正常响应下不会有该字段返回
if (!ObjectUtils.isEmpty(element) && SUCCESS_CODE != element.getAsInt()) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
// 是否为运力方错误响应
JsonElement delivery = jsonObject.get(SF_ERR_CODE);
if (!ObjectUtils.isEmpty(delivery) && SUCCESS_CODE != delivery.getAsInt()) {
throw new WxErrorException(jsonObject.get(SF_ERR_MSG).getAsString());
}
// 解析成对应响应对象
return WxMaDeliveryBaseResponse.fromJson(responseContent, valueType);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaOpenApiServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaOpenApiServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaOpenApiService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.openapi.WxMiniGetApiQuotaResult;
import cn.binarywang.wx.miniapp.bean.openapi.WxMiniGetRidInfoResult;
import cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser;
import static me.chanjar.weixin.common.api.WxConsts.ERR_CODE;
/**
* @author shuiyihan12
* @since 2023/7/7 17:08
*/
@RequiredArgsConstructor
public class WxMaOpenApiServiceImpl implements WxMaOpenApiService {
private final WxMaService wxMaService;
private static final String REQUEST = "request";
@Override
public boolean clearQuota() throws WxErrorException {
JsonObject params = new JsonObject();
params.addProperty("appid", this.wxMaService.getWxMaConfig().getAppid());
String responseContent = this.wxMaService.post(WxMaApiUrlConstants.OpenApi.CLEAR_QUOTA, params.toString());
parseErrorResponse(responseContent);
return true;
}
@Override
public WxMiniGetApiQuotaResult getApiQuota(String cgiPath) throws WxErrorException {
JsonObject params = new JsonObject();
params.addProperty("cgi_path", cgiPath);
String responseContent = this.wxMaService.post(WxMaApiUrlConstants.OpenApi.GET_API_QUOTA, params.toString());
parseErrorResponse(responseContent);
return WxMaGsonBuilder.create().fromJson(GsonParser.parse(responseContent), WxMiniGetApiQuotaResult.class);
}
@Override
public WxMiniGetRidInfoResult getRidInfo(String rid) throws WxErrorException {
JsonObject params = new JsonObject();
params.addProperty("rid", rid);
String responseContent = this.wxMaService.post(WxMaApiUrlConstants.OpenApi.GET_RID_INFO, params.toString());
parseErrorResponse(responseContent);
JsonObject response = GsonParser.parse(responseContent);
if (response.has(REQUEST)) {
return WxMaGsonBuilder.create().fromJson(response.getAsJsonObject(REQUEST), WxMiniGetRidInfoResult.class);
}
return null;
}
@Override
public boolean clearQuotaByAppSecret() throws WxErrorException {
String url = String.format(WxMaApiUrlConstants.OpenApi.CLEAR_QUOTA_BY_APP_SECRET, this.wxMaService.getWxMaConfig().getAppid(), this.wxMaService.getWxMaConfig().getSecret());
String responseContent = this.wxMaService.post(url, "");
parseErrorResponse(responseContent);
return true;
}
private void parseErrorResponse(String response) throws WxErrorException {
JsonObject jsonObject = GsonParser.parse(response);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(response, WxType.MiniApp));
}
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopCatServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopCatServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.WxMaShopCatService;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopCatGetResponse;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Cat.GET_CAT;
import static me.chanjar.weixin.common.api.WxConsts.ERR_CODE;
/**
* @author liming1019
*/
@RequiredArgsConstructor
@Slf4j
public class WxMaShopCatServiceImpl implements WxMaShopCatService {
private final WxMaService wxMaService;
@Override
public WxMaShopCatGetResponse getCat() throws WxErrorException {
String responseContent = this.wxMaService.post(GET_CAT, new JsonObject());
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopCatGetResponse.class);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaServiceHttpClientImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaServiceHttpClientImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaStableAccessTokenRequest;
import cn.binarywang.wx.miniapp.config.WxMaConfig;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.util.http.HttpClientType;
import me.chanjar.weixin.common.util.http.apache.ApacheBasicResponseHandler;
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpHost;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import java.io.IOException;
/**
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
@Slf4j
public class WxMaServiceHttpClientImpl extends BaseWxMaServiceImpl {
private CloseableHttpClient httpClient;
private HttpHost httpProxy;
@Override
public void initHttp() {
WxMaConfig configStorage = this.getWxMaConfig();
ApacheHttpClientBuilder apacheHttpClientBuilder = configStorage.getApacheHttpClientBuilder();
if (null == apacheHttpClientBuilder) {
apacheHttpClientBuilder = DefaultApacheHttpClientBuilder.get();
}
apacheHttpClientBuilder.httpProxyHost(configStorage.getHttpProxyHost())
.httpProxyPort(configStorage.getHttpProxyPort())
.httpProxyUsername(configStorage.getHttpProxyUsername())
.httpProxyPassword(configStorage.getHttpProxyPassword());
if (configStorage.getHttpProxyHost() != null && configStorage.getHttpProxyPort() > 0) {
this.httpProxy = new HttpHost(configStorage.getHttpProxyHost(), configStorage.getHttpProxyPort());
}
this.httpClient = apacheHttpClientBuilder.build();
}
@Override
public CloseableHttpClient getRequestHttpClient() {
return httpClient;
}
@Override
public HttpHost getRequestHttpProxy() {
return httpProxy;
}
@Override
public HttpClientType getRequestType() {
return HttpClientType.APACHE_HTTP;
}
@Override
protected String doGetAccessTokenRequest() throws IOException {
String url = StringUtils.isNotEmpty(this.getWxMaConfig().getAccessTokenUrl()) ?
this.getWxMaConfig().getAccessTokenUrl() :
WxMaService.GET_ACCESS_TOKEN_URL.replace(
WxMaConfig.DEFAULT_API_HOST_URL, this.getWxMaConfig().getEffectiveApiHostUrl());
url = String.format(url, this.getWxMaConfig().getAppid(), this.getWxMaConfig().getSecret());
HttpGet httpGet = new HttpGet(url);
if (this.getRequestHttpProxy() != null) {
RequestConfig config = RequestConfig.custom().setProxy(this.getRequestHttpProxy()).build();
httpGet.setConfig(config);
}
return getRequestHttpClient().execute(httpGet, ApacheBasicResponseHandler.INSTANCE);
}
@Override
protected String doGetStableAccessTokenRequest(boolean forceRefresh) throws IOException {
String url = StringUtils.isNotEmpty(this.getWxMaConfig().getAccessTokenUrl()) ?
this.getWxMaConfig().getAccessTokenUrl() :
GET_STABLE_ACCESS_TOKEN.replace(
WxMaConfig.DEFAULT_API_HOST_URL, this.getWxMaConfig().getEffectiveApiHostUrl());
HttpPost httpPost = new HttpPost(url);
if (this.getRequestHttpProxy() != null) {
RequestConfig config = RequestConfig.custom().setProxy(this.getRequestHttpProxy()).build();
httpPost.setConfig(config);
}
WxMaStableAccessTokenRequest wxMaAccessTokenRequest = new WxMaStableAccessTokenRequest();
wxMaAccessTokenRequest.setAppid(this.getWxMaConfig().getAppid());
wxMaAccessTokenRequest.setSecret(this.getWxMaConfig().getSecret());
wxMaAccessTokenRequest.setGrantType("client_credential");
wxMaAccessTokenRequest.setForceRefresh(forceRefresh);
httpPost.setEntity(new StringEntity(wxMaAccessTokenRequest.toJson(), ContentType.APPLICATION_JSON));
return getRequestHttpClient().execute(httpPost, ApacheBasicResponseHandler.INSTANCE);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaLiveServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaLiveServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaLiveService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.live.*;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.common.base.Joiner;
import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Broadcast.Room;
import static me.chanjar.weixin.common.api.WxConsts.ERR_CODE;
/**
* <pre>
* Created by yjwang on 2020/4/5.
* </pre>
*
* @author <a href="https://github.com/yjwang3300300">yjwang</a>
*/
@Slf4j
@RequiredArgsConstructor
public class WxMaLiveServiceImpl implements WxMaLiveService {
private static final String ROOM_ID = "roomId";
private final WxMaService wxMaService;
@Override
public WxMaCreateRoomResult createRoom(WxMaLiveRoomInfo roomInfo) throws WxErrorException {
try {
String responseContent = this.wxMaService.post(Room.CREATE_ROOM, WxMaGsonBuilder.create().toJson(roomInfo));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaCreateRoomResult.class);
} catch (WxErrorException e) {
if (e.getError().getErrorCode() == 300036) {
return WxMaGsonBuilder.create().fromJson(e.getError().getJson(), WxMaCreateRoomResult.class);
} else {
throw e;
}
}
}
@Override
public boolean deleteRoom(Integer roomId) throws WxErrorException {
Map<String, Object> map = new HashMap<>(2);
map.put("id", roomId);
String responseContent = this.wxMaService.post(Room.DELETE_ROOM, WxMaGsonBuilder.create().toJson(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return true;
}
@Override
public boolean editRoom(WxMaLiveRoomInfo roomInfo) throws WxErrorException {
String responseContent = this.wxMaService.post(Room.EDIT_ROOM, WxMaGsonBuilder.create().toJson(roomInfo));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return true;
}
@Override
public String getPushUrl(Integer roomId) throws WxErrorException {
Map<String, Object> map = new HashMap<>(2);
map.put(ROOM_ID, roomId);
String responseContent = this.wxMaService.get(Room.GET_PUSH_URL, Joiner.on("&").withKeyValueSeparator("=").join(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return jsonObject.get("pushAddr").getAsString();
}
@Override
public WxMaLiveSharedCode getSharedCode(Integer roomId, String params) throws WxErrorException {
Map<String, Object> map = new HashMap<>(2);
map.put(ROOM_ID, roomId);
if (null != params) {
map.put("params", params);
}
String responseContent = this.wxMaService.get(Room.GET_SHARED_CODE, Joiner.on("&").withKeyValueSeparator("=").join(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaLiveSharedCode.class);
}
@Override
public List<WxMaLiveResult.RoomInfo> getLiveInfos() throws WxErrorException {
List<WxMaLiveResult.RoomInfo> results = new ArrayList<>();
int start = 0;
Integer limit = 80;
Integer total = 0;
WxMaLiveResult liveInfo;
do {
if (total != 0 && total <= start) {
break;
}
liveInfo = getLiveInfo(start, limit);
if (liveInfo == null) {
return null;
}
results.addAll(liveInfo.getRoomInfos());
total = liveInfo.getTotal();
start = results.size();
try {
Thread.sleep(100);
} catch (InterruptedException e) {
log.error("InterruptedException", e);
}
} while (results.size() <= total);
return results;
}
@Override
public WxMaLiveResult getLiveInfo(Integer start, Integer limit) throws WxErrorException {
JsonObject jsonObject = getLiveInfo(start, limit, null);
return WxMaLiveResult.fromJson(jsonObject.toString());
}
@Override
public WxMaLiveResult getLiveReplay(String action, Integer roomId, Integer start, Integer limit) throws WxErrorException {
Map<String, Object> map = new HashMap<>(4);
map.put("action", action);
map.put("room_id", roomId);
JsonObject jsonObject = getLiveInfo(start, limit, map);
return WxMaLiveResult.fromJson(jsonObject.toString());
}
private JsonObject getLiveInfo(Integer start, Integer limit, Map<String, Object> map) throws WxErrorException {
if (map == null) {
map = new HashMap<>(2);
}
map.put("start", start);
map.put("limit", limit);
String responseContent = wxMaService.post(Room.GET_LIVE_INFO, WxMaGsonBuilder.create().toJson(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return jsonObject;
}
@Override
public WxMaLiveResult getLiveReplay(Integer roomId, Integer start, Integer limit) throws WxErrorException {
return getLiveReplay("get_replay", roomId, start, limit);
}
@Override
public boolean addGoodsToRoom(Integer roomId, List<Integer> goodsIds) throws WxErrorException {
Map<String, Object> map = new HashMap<>(2);
map.put(ROOM_ID, roomId);
map.put("ids", goodsIds);
String responseContent = this.wxMaService.post(Room.ADD_GOODS, WxMaGsonBuilder.create().toJson(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return true;
}
@Override
public boolean addAssistant(Integer roomId, List<WxMaLiveAssistantInfo> users) throws WxErrorException {
Map<String, Object> map = new HashMap<>(2);
map.put(ROOM_ID, roomId);
map.put("users", users);
String responseContent = this.wxMaService.post(Room.ADD_ASSISTANT, WxMaGsonBuilder.create().toJson(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return true;
}
@Override
public boolean modifyAssistant(Integer roomId, String username, String nickname) throws WxErrorException {
Map<String, Object> map = new HashMap<>(2);
map.put(ROOM_ID, roomId);
map.put("username", username);
map.put("nickname", nickname);
String responseContent = this.wxMaService.post(Room.MODIFY_ASSISTANT, WxMaGsonBuilder.create().toJson(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return true;
}
@Override
public boolean removeAssistant(Integer roomId, String username) throws WxErrorException {
Map<String, Object> map = new HashMap<>(2);
map.put(ROOM_ID, roomId);
map.put("username", username);
String responseContent = this.wxMaService.post(Room.REMOVE_ASSISTANT, WxMaGsonBuilder.create().toJson(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return true;
}
@Override
public List<WxMaAssistantResult.Assistant> getAssistantList(Integer roomId) throws WxErrorException {
Map<String, Object> map = new HashMap<>(2);
map.put(ROOM_ID, roomId);
String responseContent = this.wxMaService.get(Room.GET_ASSISTANT_LIST,
Joiner.on("&").withKeyValueSeparator("=").join(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaAssistantResult.fromJson(responseContent).getList();
}
@Override
public boolean addSubanchor(Integer roomId, String username) throws WxErrorException {
Map<String, Object> map = new HashMap<>(2);
map.put(ROOM_ID, roomId);
map.put("username", username);
String responseContent = this.wxMaService.post(Room.ADD_SUBANCHOR, WxMaGsonBuilder.create().toJson(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return true;
}
@Override
public boolean modifySubanchor(Integer roomId, String username) throws WxErrorException {
Map<String, Object> map = new HashMap<>(2);
map.put(ROOM_ID, roomId);
map.put("username", username);
String responseContent = this.wxMaService.post(Room.MODIFY_SUBANCHOR, WxMaGsonBuilder.create().toJson(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return true;
}
@Override
public boolean deleteSubanchor(Integer roomId) throws WxErrorException {
Map<String, Object> map = new HashMap<>(1);
map.put(ROOM_ID, roomId);
String responseContent = this.wxMaService.post(Room.DELETE_SUBANCHOR, WxMaGsonBuilder.create().toJson(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return true;
}
@Override
public String getSubanchor(Integer roomId) throws WxErrorException {
Map<String, Object> map = new HashMap<>(1);
map.put(ROOM_ID, roomId);
String responseContent = this.wxMaService.get(Room.GET_SUBANCHOR, Joiner.on("&").withKeyValueSeparator("=").join(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return jsonObject.get("username").getAsString();
}
@Override
public boolean updatefeedpublic(Integer roomId, Integer isFeedsPublic) throws WxErrorException {
Map<String, Object> map = new HashMap<>(2);
map.put(ROOM_ID, roomId);
map.put("isFeedsPublic", isFeedsPublic);
String responseContent = this.wxMaService.post(Room.UPDATE_FEED_PUBLIC, WxMaGsonBuilder.create().toJson(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return true;
}
@Override
public boolean updatereplay(Integer roomId, Integer closeReplay) throws WxErrorException {
Map<String, Object> map = new HashMap<>(2);
map.put(ROOM_ID, roomId);
map.put("closeReplay", closeReplay);
String responseContent = this.wxMaService.post(Room.UPDATE_REPLAY, WxMaGsonBuilder.create().toJson(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return true;
}
@Override
public boolean updatekf(Integer roomId, Integer closeKf) throws WxErrorException {
Map<String, Object> map = new HashMap<>(2);
map.put(ROOM_ID, roomId);
map.put("closeKf", closeKf);
String responseContent = this.wxMaService.post(Room.UPDATE_KF, WxMaGsonBuilder.create().toJson(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return true;
}
@Override
public boolean updatecomment(Integer roomId, Integer banComment) throws WxErrorException {
Map<String, Object> map = new HashMap<>(2);
map.put(ROOM_ID, roomId);
map.put("banComment", banComment);
String responseContent = this.wxMaService.post(Room.UPDATE_COMMENT, WxMaGsonBuilder.create().toJson(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return true;
}
@Override
public boolean onsale(Integer roomId, Integer goodsId, Integer onSale) throws WxErrorException {
Map<String, Object> map = new HashMap<>(3);
map.put(ROOM_ID, roomId);
map.put("goodsId", goodsId);
map.put("onSale", onSale);
String responseContent = this.wxMaService.post(Room.ONSALE, WxMaGsonBuilder.create().toJson(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return true;
}
@Override
public boolean deleteInRoom(Integer roomId, Integer goodsId) throws WxErrorException {
Map<String, Object> map = new HashMap<>(2);
map.put(ROOM_ID, roomId);
map.put("goodsId", goodsId);
String responseContent = this.wxMaService.post(Room.DELETE_IN_ROOM, WxMaGsonBuilder.create().toJson(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return true;
}
@Override
public boolean push(Integer roomId, Integer goodsId) throws WxErrorException {
Map<String, Object> map = new HashMap<>(2);
map.put(ROOM_ID, roomId);
map.put("goodsId", goodsId);
String responseContent = this.wxMaService.post(Room.PUSH, WxMaGsonBuilder.create().toJson(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return true;
}
@Override
public boolean sort(Integer roomId, List<Map<String,String>> goods) throws WxErrorException {
Map<String, Object> map = new HashMap<>(2);
map.put(ROOM_ID, roomId);
map.put("goods", goods);
String responseContent = this.wxMaService.post(Room.SORT, WxMaGsonBuilder.create().toJson(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return true;
}
@Override
public String getVideo(Integer roomId, Integer goodsId) throws WxErrorException {
Map<String, Object> map = new HashMap<>(2);
map.put(ROOM_ID, roomId);
map.put("goodsId", goodsId);
String responseContent = this.wxMaService.post(Room.GET_VIDEO, WxMaGsonBuilder.create().toJson(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return jsonObject.get("url").getAsString();
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShareServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShareServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.WxMaShareService;
import cn.binarywang.wx.miniapp.bean.WxMaGroupEnterInfo;
import cn.binarywang.wx.miniapp.bean.WxMaShareInfo;
import cn.binarywang.wx.miniapp.util.crypt.WxMaCryptUtils;
import lombok.RequiredArgsConstructor;
/**
* @author zhfish
*/
@RequiredArgsConstructor
public class WxMaShareServiceImpl implements WxMaShareService {
private final WxMaService service;
@Override
public WxMaShareInfo getShareInfo(String sessionKey, String encryptedData, String ivStr) {
return WxMaShareInfo.fromJson(WxMaCryptUtils.decrypt(sessionKey, encryptedData, ivStr));
}
@Override
public WxMaGroupEnterInfo getGroupEnterInfo(String sessionKey, String encryptedData, String ivStr) {
return WxMaGroupEnterInfo.fromJson(WxMaCryptUtils.decrypt(sessionKey, encryptedData, ivStr));
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaExpressServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaExpressServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaExpressService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.express.WxMaExpressAccount;
import cn.binarywang.wx.miniapp.bean.express.WxMaExpressDelivery;
import cn.binarywang.wx.miniapp.bean.express.WxMaExpressPath;
import cn.binarywang.wx.miniapp.bean.express.WxMaExpressPrinter;
import cn.binarywang.wx.miniapp.bean.express.request.*;
import cn.binarywang.wx.miniapp.bean.express.result.WxMaExpressInfoResult;
import cn.binarywang.wx.miniapp.bean.express.result.WxMaExpressOrderInfoResult;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Express.*;
/**
* @author <a href="https://github.com/mr-xiaoyu">xiaoyu</a>
* @since 2019-11-26
*/
@RequiredArgsConstructor
public class WxMaExpressServiceImpl implements WxMaExpressService {
private final WxMaService service;
@Override
public List<WxMaExpressDelivery> getAllDelivery() throws WxErrorException {
String responseContent = this.service.get(ALL_DELIVERY_URL, null);
return WxMaExpressDelivery.fromJson(responseContent);
}
@Override
public List<WxMaExpressAccount> getAllAccount() throws WxErrorException {
String responseContent = this.service.get(ALL_ACCOUNT_URL, null);
return WxMaExpressAccount.fromJsonList(responseContent);
}
@Override
public WxMaExpressInfoResult bindAccount(WxMaExpressBindAccountRequest wxMaExpressBindAccountRequest) throws WxErrorException {
return WxMaExpressInfoResult.fromJson(this.service.post(BIND_ACCOUNT_URL, wxMaExpressBindAccountRequest.toJson()));
}
@Override
public Integer getQuota(WxMaExpressBindAccountRequest wxMaExpressBindAccountRequest) throws WxErrorException {
String responseContent = this.service.post(GET_QUOTA_URL, wxMaExpressBindAccountRequest.toJson());
WxMaExpressAccount account = WxMaExpressAccount.fromJson(responseContent);
return account.getQuotaNum();
}
@Override
public void updatePrinter(WxMaExpressPrinterUpdateRequest wxMaExpressPrinterUpdateRequest) throws WxErrorException {
this.service.post(UPDATE_PRINTER_URL, wxMaExpressPrinterUpdateRequest.toJson());
}
@Override
public WxMaExpressPrinter getPrinter() throws WxErrorException {
String responseContent = this.service.get(GET_PRINTER_URL, null);
return WxMaExpressPrinter.fromJson(responseContent);
}
@Override
public WxMaExpressOrderInfoResult addOrder(WxMaExpressAddOrderRequest wxMaExpressAddOrderRequest) throws WxErrorException {
String responseContent = this.service.post(ADD_ORDER_URL, wxMaExpressAddOrderRequest.toJson());
return WxMaExpressOrderInfoResult.fromJson(responseContent);
}
@Override
public List<WxMaExpressOrderInfoResult> batchGetOrder(List<WxMaExpressGetOrderRequest> requests) throws WxErrorException {
Map<String, Object> param = new HashMap<>(1);
param.put("order_list", requests);
String responseContent = this.service.post(BATCH_GET_ORDER_URL, WxMaGsonBuilder.create().toJson(param));
return WxMaExpressOrderInfoResult.toList(responseContent);
}
@Override
public void cancelOrder(WxMaExpressGetOrderRequest wxMaExpressGetOrderRequest) throws WxErrorException {
this.service.post(CANCEL_ORDER_URL, wxMaExpressGetOrderRequest.toJson());
}
@Override
public WxMaExpressOrderInfoResult getOrder(WxMaExpressGetOrderRequest wxMaExpressGetOrderRequest) throws WxErrorException {
String responseContent = this.service.post(GET_ORDER_URL, wxMaExpressGetOrderRequest.toJson());
return WxMaExpressOrderInfoResult.fromJson(responseContent);
}
@Override
public WxMaExpressPath getPath(WxMaExpressGetOrderRequest wxMaExpressGetOrderRequest) throws WxErrorException {
String responseContent = this.service.post(GET_PATH_URL, wxMaExpressGetOrderRequest.toJson());
return WxMaExpressPath.fromJson(responseContent);
}
@Override
public void testUpdateOrder(WxMaExpressTestUpdateOrderRequest wxMaExpressTestUpdateOrderRequest) throws WxErrorException {
this.service.post(TEST_UPDATE_ORDER_URL, wxMaExpressTestUpdateOrderRequest.toJson());
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaMsgServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaMsgServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaMsgService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaKefuMessage;
import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
import cn.binarywang.wx.miniapp.bean.WxMaUniformMessage;
import cn.binarywang.wx.miniapp.bean.WxMaUpdatableMsg;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Msg.*;
/**
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
@RequiredArgsConstructor
public class WxMaMsgServiceImpl implements WxMaMsgService {
private final WxMaService service;
@Override
public boolean sendKefuMsg(WxMaKefuMessage message) throws WxErrorException {
String responseContent = this.service.post(KEFU_MESSAGE_SEND_URL, message.toJson());
return responseContent != null;
}
@Override
public void sendSubscribeMsg(WxMaSubscribeMessage subscribeMessage) throws WxErrorException {
String responseContent = this.service.post(SUBSCRIBE_MSG_SEND_URL, subscribeMessage.toJson());
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
}
@Override
public void sendUniformMsg(WxMaUniformMessage uniformMessage) throws WxErrorException {
String responseContent = this.service.post(UNIFORM_MSG_SEND_URL, uniformMessage.toJson());
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
}
@Override
public JsonObject createUpdatableMessageActivityId() throws WxErrorException {
final String responseContent = this.service.get(ACTIVITY_ID_CREATE_URL, null);
return GsonParser.parse(responseContent);
}
@Override
public void setUpdatableMsg(WxMaUpdatableMsg msg) throws WxErrorException {
this.service.post(UPDATABLE_MSG_SEND_URL, WxMaGsonBuilder.create().toJson(msg));
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaImgProcServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaImgProcServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaService;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.bean.imgproc.WxImgProcAiCropResult;
import me.chanjar.weixin.common.bean.imgproc.WxImgProcQrCodeResult;
import me.chanjar.weixin.common.bean.imgproc.WxImgProcSuperResolutionResult;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.requestexecuter.ocr.OcrDiscernRequestExecutor;
import me.chanjar.weixin.common.service.WxImgProcService;
import org.apache.commons.lang3.StringUtils;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.ImgProc.*;
/**
* 图像处理接口实现.
*
* @author Theo Nie
*/
@RequiredArgsConstructor
public class WxMaImgProcServiceImpl implements WxImgProcService {
private final WxMaService service;
@Override
public WxImgProcQrCodeResult qrCode(String imgUrl) throws WxErrorException {
try {
imgUrl = URLEncoder.encode(imgUrl, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
//ignore
}
final String result = this.service.post(String.format(QRCODE, imgUrl), "");
return WxImgProcQrCodeResult.fromJson(result);
}
@Override
public WxImgProcQrCodeResult qrCode(File imgFile) throws WxErrorException {
String result = this.service.execute(OcrDiscernRequestExecutor.create(this.service.getRequestHttp()),
FILE_QRCODE, imgFile);
return WxImgProcQrCodeResult.fromJson(result);
}
@Override
public WxImgProcSuperResolutionResult superResolution(String imgUrl) throws WxErrorException {
try {
imgUrl = URLEncoder.encode(imgUrl, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
//ignore
}
final String result = this.service.get(String.format(SUPER_RESOLUTION, imgUrl), null);
return WxImgProcSuperResolutionResult.fromJson(result);
}
@Override
public WxImgProcSuperResolutionResult superResolution(File imgFile) throws WxErrorException {
String result = this.service.execute(OcrDiscernRequestExecutor.create(this.service.getRequestHttp()),
FILE_SUPER_RESOLUTION, imgFile);
return WxImgProcSuperResolutionResult.fromJson(result);
}
@Override
public WxImgProcAiCropResult aiCrop(String imgUrl) throws WxErrorException {
return this.aiCrop(imgUrl, "");
}
@Override
public WxImgProcAiCropResult aiCrop(String imgUrl, String ratios) throws WxErrorException {
try {
imgUrl = URLEncoder.encode(imgUrl, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
//ignore
}
if (StringUtils.isEmpty(ratios)) {
ratios = "";
}
final String result = this.service.post(String.format(AI_CROP, imgUrl, ratios), "");
return WxImgProcAiCropResult.fromJson(result);
}
@Override
public WxImgProcAiCropResult aiCrop(File imgFile) throws WxErrorException {
return this.aiCrop(imgFile, "");
}
@Override
public WxImgProcAiCropResult aiCrop(File imgFile, String ratios) throws WxErrorException {
if (StringUtils.isEmpty(ratios)) {
ratios = "";
}
String result = this.service.execute(OcrDiscernRequestExecutor.create(this.service.getRequestHttp()),
String.format(FILE_AI_CROP, ratios), imgFile);
return WxImgProcAiCropResult.fromJson(result);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaKefuServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaKefuServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaKefuService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.kefu.WxMaKfInfo;
import cn.binarywang.wx.miniapp.bean.kefu.WxMaKfList;
import cn.binarywang.wx.miniapp.bean.kefu.WxMaKfSession;
import cn.binarywang.wx.miniapp.bean.kefu.WxMaKfSessionList;
import cn.binarywang.wx.miniapp.bean.kefu.request.WxMaKfAccountRequest;
import cn.binarywang.wx.miniapp.bean.kefu.request.WxMaKfSessionRequest;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
/**
* 小程序客服管理服务实现.
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
@RequiredArgsConstructor
public class WxMaKefuServiceImpl implements WxMaKefuService {
// 小程序客服管理接口URL
private static final String KFLIST_GET_URL = "https://api.weixin.qq.com/cgi-bin/customservice/getkflist";
private static final String KFACCOUNT_ADD_URL = "https://api.weixin.qq.com/customservice/kfaccount/add";
private static final String KFACCOUNT_UPDATE_URL = "https://api.weixin.qq.com/customservice/kfaccount/update";
private static final String KFACCOUNT_DEL_URL = "https://api.weixin.qq.com/customservice/kfaccount/del?kf_account=%s";
private static final String KFSESSION_CREATE_URL = "https://api.weixin.qq.com/customservice/kfsession/create";
private static final String KFSESSION_CLOSE_URL = "https://api.weixin.qq.com/customservice/kfsession/close";
private static final String KFSESSION_GET_URL = "https://api.weixin.qq.com/customservice/kfsession/getsession?openid=%s";
private static final String KFSESSION_LIST_URL = "https://api.weixin.qq.com/customservice/kfsession/getsessionlist?kf_account=%s";
private final WxMaService service;
@Override
public WxMaKfList kfList() throws WxErrorException {
String responseContent = this.service.get(KFLIST_GET_URL, null);
return WxMaKfList.fromJson(responseContent);
}
@Override
public boolean kfAccountAdd(WxMaKfAccountRequest request) throws WxErrorException {
String responseContent = this.service.post(KFACCOUNT_ADD_URL, request.toJson());
return responseContent != null;
}
@Override
public boolean kfAccountUpdate(WxMaKfAccountRequest request) throws WxErrorException {
String responseContent = this.service.post(KFACCOUNT_UPDATE_URL, request.toJson());
return responseContent != null;
}
@Override
public boolean kfAccountDel(String kfAccount) throws WxErrorException {
String url = String.format(KFACCOUNT_DEL_URL, kfAccount);
String responseContent = this.service.get(url, null);
return responseContent != null;
}
@Override
public boolean kfSessionCreate(String openid, String kfAccount) throws WxErrorException {
WxMaKfSessionRequest request = WxMaKfSessionRequest.builder()
.kfAccount(kfAccount)
.openid(openid)
.build();
String responseContent = this.service.post(KFSESSION_CREATE_URL, request.toJson());
return responseContent != null;
}
@Override
public boolean kfSessionClose(String openid, String kfAccount) throws WxErrorException {
WxMaKfSessionRequest request = WxMaKfSessionRequest.builder()
.kfAccount(kfAccount)
.openid(openid)
.build();
String responseContent = this.service.post(KFSESSION_CLOSE_URL, request.toJson());
return responseContent != null;
}
@Override
public WxMaKfSession kfSessionGet(String openid) throws WxErrorException {
String url = String.format(KFSESSION_GET_URL, openid);
String responseContent = this.service.get(url, null);
return WxMaKfSession.fromJson(responseContent);
}
@Override
public WxMaKfSessionList kfSessionList(String kfAccount) throws WxErrorException {
String url = String.format(KFSESSION_LIST_URL, kfAccount);
String responseContent = this.service.get(url, null);
return WxMaKfSessionList.fromJson(responseContent);
}
} | java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopRegisterServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopRegisterServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.WxMaShopRegisterService;
import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopRegisterApplySceneRequest;
import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopRegisterFinishAccessInfoRequest;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopBaseResponse;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopRegisterCheckResponse;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Register.*;
/**
* @author liming1019
*/
@RequiredArgsConstructor
@Slf4j
public class WxMaShopRegisterServiceImpl implements WxMaShopRegisterService {
private static final String ERR_CODE = "errcode";
private final WxMaService wxMaService;
@Override
public WxMaShopBaseResponse registerApply() throws WxErrorException {
String responseContent = this.wxMaService.post(REGISTER_APPLY, new JsonObject());
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopBaseResponse.class);
}
@Override
public WxMaShopRegisterCheckResponse registerCheck() throws WxErrorException {
String responseContent = this.wxMaService.post(REGISTER_CHECK, new JsonObject());
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopRegisterCheckResponse.class);
}
@Override
public WxMaShopBaseResponse registerFinishAccessInfo(WxMaShopRegisterFinishAccessInfoRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(REGISTER_FINISH_ACCESS_INFO, request);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopBaseResponse.class);
}
@Override
public WxMaShopBaseResponse registerApplyScene(WxMaShopRegisterApplySceneRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(REGISTER_APPLY_SCENE, request);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopBaseResponse.class);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaCustomserviceWorkServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaCustomserviceWorkServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaCustomserviceWorkService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.customservice.WxMaCustomserviceResult;
import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
/**
* <pre>
* 小程序 - 微信客服 相关接口
* 负责处理 https://api.weixin.qq.com/customservice/work/**
* 文档:https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/kf-work/getKfWorkBound.html
* 绑定的企业ID,需和小程序主体一致。
* 目前仅支持绑定非个人小程序。
* Created by tryking123 on 2025/8/18.
* </pre>
*
* @author <a href="https://github.com/tryking123">tryking123</a>
*/
@RequiredArgsConstructor
public class WxMaCustomserviceWorkServiceImpl implements WxMaCustomserviceWorkService {
private static final String CORPID = "corpid";
private final WxMaService service;
@Override
public WxMaCustomserviceResult getCustomservice() throws WxErrorException {
String responseContent = this.service.get(GET_CUSTOMSERVICE_URL, null);
return WxMaCustomserviceResult.fromJson(responseContent);
}
@Override
public WxMaCustomserviceResult bindCustomservice(String corpid) throws WxErrorException {
JsonObject paramJson = new JsonObject();
paramJson.addProperty(CORPID, corpid);
String response = this.service.post(BIND_CUSTOMSERVICE_URL, paramJson);
return WxMaCustomserviceResult.fromJson(response);
}
@Override
public WxMaCustomserviceResult unbindCustomservice(String corpid) throws WxErrorException {
JsonObject paramJson = new JsonObject();
paramJson.addProperty(CORPID, corpid);
String response = this.service.post(UNBIND_CUSTOMSERVICE_URL, paramJson);
return WxMaCustomserviceResult.fromJson(response);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaSettingServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaSettingServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.WxMaSettingService;
import cn.binarywang.wx.miniapp.bean.WxMaDomainAction;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import java.util.HashMap;
import java.util.Map;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Setting.*;
/**
* @author <a href="https://github.com/charmingoh">Charming</a>
* @since 2018-04-27 15:46
*/
@RequiredArgsConstructor
public class WxMaSettingServiceImpl implements WxMaSettingService {
private final WxMaService wxMaService;
@Override
public WxMaDomainAction modifyDomain(WxMaDomainAction domainAction) throws WxErrorException {
String responseContent = this.wxMaService.post(MODIFY_DOMAIN_URL, domainAction.toJson());
return WxMaDomainAction.fromJson(responseContent);
}
@Override
public WxMaDomainAction setWebViewDomain(WxMaDomainAction domainAction) throws WxErrorException {
String responseContent = this.wxMaService.post(SET_WEB_VIEW_DOMAIN_URL, domainAction.toJson());
return WxMaDomainAction.fromJson(responseContent);
}
@Override
public void bindTester(String wechatId) throws WxErrorException {
Map<String, Object> param = new HashMap<>(1);
param.put("wechatid", wechatId);
this.wxMaService.post(BIND_TESTER_URL, WxMaGsonBuilder.create().toJson(param));
}
@Override
public void unbindTester(String wechatId) throws WxErrorException {
Map<String, Object> param = new HashMap<>(1);
param.put("wechatid", wechatId);
this.wxMaService.post(UNBIND_TESTER_URL, WxMaGsonBuilder.create().toJson(param));
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaIntracityServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaIntracityServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Intracity;
import static me.chanjar.weixin.common.api.WxConsts.ERR_CODE;
import cn.binarywang.wx.miniapp.api.WxMaIntracityService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.intractiy.*;
import com.google.gson.*;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
import java.util.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@RequiredArgsConstructor
@Slf4j
public class WxMaIntracityServiceImpl implements WxMaIntracityService {
private final WxMaService wxMaService;
private static final Logger logger = LoggerFactory.getLogger(WxMaIntracityServiceImpl.class);
private final Gson gson =
new GsonBuilder()
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
.create();
private void checkStringResponse(String response) throws WxErrorException {
JsonObject respObj = GsonParser.parse(response);
if (respObj.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(response, WxType.MiniApp));
}
}
@Override
public void apply() throws WxErrorException {
String response = this.wxMaService.post(Intracity.APPLY_URL, "{}");
checkStringResponse(response);
}
@Override
public String createStore(WxMaStore store) throws WxErrorException {
if (store.getOutStoreId() == null) {
throw new IllegalArgumentException("创建门店时outStoreId不能为空");
}
if (store.getWxStoreId() != null) {
throw new IllegalArgumentException("创建门店时wxStoreId只能是null");
}
String response = this.wxMaService.postWithSignature(Intracity.CREATE_STORE_URL, store);
Map<?, ?> map = gson.fromJson(response, Map.class);
return (String) map.get("wx_store_id");
}
@Override
public void updateStore(WxMaStore store) throws WxErrorException {
if (store.getWxStoreId() == null && store.getOutStoreId() == null) {
throw new IllegalArgumentException("更新门店时wxStoreId 或 outStoreId 至少要有一个不为null");
}
JsonObject request = new JsonObject();
Map<String, String> keys = new HashMap<>();
if (store.getWxStoreId() != null) {
keys.put("wx_store_id", store.getWxStoreId());
} else {
keys.put("out_store_id", store.getOutStoreId());
}
request.add("keys", gson.toJsonTree(keys));
Map<String, Object> updateContent = new HashMap<>();
if (store.getStoreName() != null) {
updateContent.put("store_name", store.getStoreName());
}
if (store.getOrderPattern() == 1 || store.getOrderPattern() == 2) {
updateContent.put("order_pattern", store.getOrderPattern());
}
if (store.getServiceTransPrefer() != null) {
updateContent.put("service_trans_prefer", store.getServiceTransPrefer());
}
if (store.getAddressInfo() != null) {
updateContent.put("address_info", store.getAddressInfo());
}
request.add("content", gson.toJsonTree(updateContent));
String response = this.wxMaService.postWithSignature(Intracity.UPDATE_STORE_URL, request);
checkStringResponse(response);
}
@Override
public List<WxMaStore> listAllStores() throws WxErrorException {
return queryStore(null, null);
}
@Override
public WxMaStore queryStoreByWxStoreId(String wxStoreId) throws WxErrorException {
List<WxMaStore> list = queryStore(wxStoreId, null);
return list.isEmpty() ? null : list.get(0);
}
@Override
public List<WxMaStore> queryStoreByOutStoreId(String outStoreId) throws WxErrorException {
return queryStore(null, outStoreId);
}
private List<WxMaStore> queryStore(String wxStoreId, String outStoreId) throws WxErrorException {
Map<String, String> map = new HashMap<>();
if (wxStoreId != null) {
map.put("wx_store_id", wxStoreId);
} else if (outStoreId != null) {
map.put("out_store_id", outStoreId);
}
String response = this.wxMaService.postWithSignature(Intracity.QUERY_STORE_URL, map);
JsonObject jsonObject = gson.fromJson(response, JsonObject.class);
Type listType = new TypeToken<List<WxMaStore>>() {}.getType();
return gson.fromJson(jsonObject.getAsJsonArray("store_list"), listType);
}
@Override
public String storeCharge(WxMaStoreChargeRequest request) throws WxErrorException {
String response = this.wxMaService.postWithSignature(Intracity.STORE_CHARGE, request);
Map<?, ?> map = gson.fromJson(response, Map.class);
return (String) map.get("payurl");
}
@Override
public int storeRefund(WxMaStoreRefundRequest request) throws WxErrorException {
String response = this.wxMaService.postWithSignature(Intracity.STORE_REFUND, request);
Map<?, ?> map = gson.fromJson(response, Map.class);
return ((Number) map.get("refund_amount")).intValue();
}
@Override
public WxMaStoreFlowResponse<? extends WxMaStoreFlowResponse.BasicFlowRecord> queryFlow(
WxMaQueryFlowRequest request) throws WxErrorException {
if (request == null || request.getWxStoreId() == null) {
throw new IllegalArgumentException("查询请求 wxStoreId 不可为空");
}
WxMaStoreFlowResponse<? extends WxMaStoreFlowResponse.BasicFlowRecord> inst =
getFlowInstanceByType(request.getFlowType());
if (inst == null) {
throw new IllegalArgumentException("查询请求 flowType 不正确,只能是1、2、3之一");
}
String response = this.wxMaService.postWithSignature(Intracity.QUERY_FLOW, request);
WxMaStoreFlowResponse<? extends WxMaStoreFlowResponse.BasicFlowRecord> flowResponse;
flowResponse =
(WxMaStoreFlowResponse<? extends WxMaStoreFlowResponse.BasicFlowRecord>)
gson.fromJson(response, inst.getClass());
logger.debug("queryFlow: {}", flowResponse);
return flowResponse;
}
private WxMaStoreFlowResponse<? extends WxMaStoreFlowResponse.BasicFlowRecord>
getFlowInstanceByType(int flowType) {
WxMaStoreFlowResponse<? extends WxMaStoreFlowResponse.BasicFlowRecord> inst;
if (flowType == 1) {
inst = new WxMaStoreFlowResponse<WxMaStoreFlowResponse.ChargeFlowRecord>();
} else if (flowType == 2) {
inst = new WxMaStoreFlowResponse<WxMaStoreFlowResponse.RefundFlowRecord>();
} else if (flowType == 3) {
inst = new WxMaStoreFlowResponse<WxMaStoreFlowResponse.ConsumeFlowRecord>();
} else {
return null;
}
return inst;
}
@Override
public WxMaStoreBalance balanceQuery(String wxStoreId, String serviceTransId, PayMode payMode)
throws WxErrorException {
if (wxStoreId == null && (payMode == null || payMode == PayMode.STORE)) {
throw new IllegalArgumentException("payMode是PAY_MODE_STORE或null时,必须传递wxStoreId");
}
Map<String, Object> request = new HashMap<>();
if (wxStoreId != null) {
request.put("wx_store_id", wxStoreId);
}
if (serviceTransId != null) {
request.put("service_trans_id", serviceTransId);
}
if (payMode != null) {
request.put("pay_mode", payMode);
}
String response = this.wxMaService.postWithSignature(Intracity.BALANCE_QUERY, request);
WxMaStoreBalance balance = gson.fromJson(response, WxMaStoreBalance.class);
logger.debug("balance: {}", balance);
return balance;
}
public void setPayMode(PayMode payMode) throws WxErrorException {
Map<String, Object> request = new HashMap<>();
request.put("pay_mode", payMode);
request.put("appid", wxMaService.getWxMaConfig().getAppid());
String response = this.wxMaService.postWithSignature(Intracity.SET_PAY_MODE, request);
checkStringResponse(response);
}
public WxMaGetPayModeResponse getPayMode() throws WxErrorException {
Map<String, Object> request = new HashMap<>();
request.put("appid", wxMaService.getWxMaConfig().getAppid());
String response = this.wxMaService.postWithSignature(Intracity.GET_PAY_MODE, request);
return gson.fromJson(response, WxMaGetPayModeResponse.class);
}
@Override
public WxMaPreAddOrderResponse preAddOrder(WxMaPreAddOrderRequest request)
throws WxErrorException {
String response = this.wxMaService.postWithSignature(Intracity.PRE_ADD_ORDER, request);
return gson.fromJson(response, WxMaPreAddOrderResponse.class);
}
@Override
public WxMaAddOrderResponse addOrder(WxMaAddOrderRequest request) throws WxErrorException {
String response = this.wxMaService.postWithSignature(Intracity.ADD_ORDER, request);
return gson.fromJson(response, WxMaAddOrderResponse.class);
}
@Override
public WxMaOrder queryOrderByWxOrderId(String wxOrderId) throws WxErrorException {
Map<String, Object> map = new HashMap<>();
map.put("wx_order_id", wxOrderId);
String response = this.wxMaService.postWithSignature(Intracity.QUERY_ORDER, map);
return gson.fromJson(response, WxMaOrder.class);
}
@Override
public WxMaOrder queryOrderByStoreOrderId(String wxStoreId, String storeOrderId)
throws WxErrorException {
Map<String, Object> map = new HashMap<>();
map.put("wx_store_id", wxStoreId);
map.put("store_order_id", storeOrderId);
String response = this.wxMaService.postWithSignature(Intracity.QUERY_ORDER, map);
return gson.fromJson(response, WxMaOrder.class);
}
@Override
public WxMaCancelOrderResponse cancelOrderByWxOrderId(
String wxOrderId, int cancelReasonId, String cancelReason) throws WxErrorException {
Map<String, Object> map = new HashMap<>();
map.put("wx_order_id", wxOrderId);
map.put("cancel_reason_id", cancelReasonId);
if (cancelReason != null) {
map.put("cancel_reason", cancelReason);
}
String response = this.wxMaService.postWithSignature(Intracity.CANCEL_ORDER, map);
return gson.fromJson(response, WxMaCancelOrderResponse.class);
}
@Override
public WxMaCancelOrderResponse cancelOrderByStoreOrderId(
String wxStoreId, String storeOrderId, int cancelReasonId, String cancelReason)
throws WxErrorException {
Map<String, Object> map = new HashMap<>();
map.put("wx_store_id", wxStoreId);
map.put("store_order_id", storeOrderId);
map.put("cancel_reason_id", cancelReasonId);
if (cancelReason != null) {
map.put("cancel_reason", cancelReason);
}
String response = this.wxMaService.postWithSignature(Intracity.CANCEL_ORDER, map);
return gson.fromJson(response, WxMaCancelOrderResponse.class);
}
@Override
public List<WxMaTransCity> getCity(String serviceTransId) throws WxErrorException {
Map<String, Object> map = new HashMap<>();
if (serviceTransId != null) {
map.put("service_trans_id", serviceTransId);
}
String response = this.wxMaService.postWithSignature(Intracity.GET_CITY, map);
JsonObject jsonObject = gson.fromJson(response, JsonObject.class);
Type listType = new TypeToken<List<WxMaTransCity>>() {}.getType();
return gson.fromJson(jsonObject.getAsJsonArray("support_list"), listType);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaLinkServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaLinkServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaLinkService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.shortlink.GenerateShortLinkRequest;
import cn.binarywang.wx.miniapp.bean.urllink.GenerateUrlLinkRequest;
import cn.binarywang.wx.miniapp.bean.urllink.request.QueryUrlLinkRequest;
import cn.binarywang.wx.miniapp.bean.urllink.response.QueryUrlLinkResponse;
import com.google.gson.JsonObject;
import lombok.AllArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Link.GENERATE_URLLINK_URL;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Link.QUERY_URLLINK_URL;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.ShortLink.GENERATE_SHORT_LINK_URL;
/**
* 获取小程序 URL Link接口实现
* 接口文档: https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/url-link/urllink.generate.html
*
* @author <a href="https://github.com/mr-xiaoyu">xiaoyu</a>
* @since 2021-06-10
*/
@AllArgsConstructor
public class WxMaLinkServiceImpl implements WxMaLinkService {
private final WxMaService wxMaService;
@Override
public String generateUrlLink(GenerateUrlLinkRequest request) throws WxErrorException {
String result = this.wxMaService.post(GENERATE_URLLINK_URL, request);
String linkField = "url_link";
JsonObject jsonObject = GsonParser.parse(result);
if (jsonObject.has(linkField)) {
return jsonObject.get(linkField).getAsString();
}
throw new WxErrorException("无url_link");
}
@Override
public String generateShortLink(GenerateShortLinkRequest request) throws WxErrorException {
String result = this.wxMaService.post(GENERATE_SHORT_LINK_URL, request);
String linkField = "link";
JsonObject jsonObject = GsonParser.parse(result);
if (jsonObject.has(linkField)) {
return jsonObject.get(linkField).getAsString();
}
throw new WxErrorException("无link");
}
@Override
public QueryUrlLinkResponse queryUrlLink(QueryUrlLinkRequest request) throws WxErrorException {
String result = this.wxMaService.post(QUERY_URLLINK_URL, request);
return WxGsonBuilder.create().fromJson(result, QueryUrlLinkResponse.class);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaSchemeServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaSchemeServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaSchemeService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.scheme.WxMaGenerateNfcSchemeRequest;
import cn.binarywang.wx.miniapp.bean.scheme.WxMaGenerateSchemeRequest;
import com.google.gson.JsonObject;
import lombok.AllArgsConstructor;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Scheme.GENERATE_NFC_SCHEME_URL;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Scheme.GENERATE_SCHEME_URL;
/**
* @author : cofedream
* created on : 2021-01-28
*/
@AllArgsConstructor
public class WxMaSchemeServiceImpl implements WxMaSchemeService {
private final WxMaService wxMaService;
/**
* 获取小程序scheme码
* 文档地址:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/url-scheme/urlscheme.generate.html
*
* @param request 请求参数
* @throws WxErrorException 生成失败时抛出,具体错误码请看文档
*/
@Override
public String generate(WxMaGenerateSchemeRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(GENERATE_SCHEME_URL, request.toJson());
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return jsonObject.get("openlink").getAsString();
}
/**
* 获取NFC 的小程序 scheme
* 文档地址:https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/url-scheme/generateNFCScheme.html
*
* @param request 请求参数
* @throws WxErrorException 生成失败时抛出,具体错误码请看文档
*/
@Override
public String generateNFC(WxMaGenerateNfcSchemeRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(GENERATE_NFC_SCHEME_URL, request.toJson());
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return jsonObject.get("openlink").getAsString();
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopAfterSaleServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopAfterSaleServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.WxMaShopAfterSaleService;
import cn.binarywang.wx.miniapp.bean.shop.request.*;
import cn.binarywang.wx.miniapp.bean.shop.response.*;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonHelper;
import me.chanjar.weixin.common.util.json.GsonParser;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Aftersale.*;
import static me.chanjar.weixin.common.api.WxConsts.ERR_CODE;
/**
* @author boris
* @author liming1019
*/
@RequiredArgsConstructor
@Slf4j
public class WxMaShopAfterSaleServiceImpl implements WxMaShopAfterSaleService {
private final WxMaService wxMaService;
/**
* 创建售后
*
* @param request
* @return WxMaShopBaseResponse
* @throws WxErrorException
*/
@Override
public WxMaShopAfterSaleAddResponse add(WxMaShopAfterSaleAddRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(AFTERSALE_ADD, request);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopAfterSaleAddResponse.class);
}
/**
* 获取订单下售后单
*
* @param request
* @return WxMaShopAfterSaleGetResponse
* @throws WxErrorException
*/
@Override
public WxMaShopAfterSaleGetResponse get(WxMaShopAfterSaleGetRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(AFTERSALE_GET, request);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopAfterSaleGetResponse.class);
}
/**
* 获取售后单详情(EC版)
*
* @param request
* @return WxMaShopEcAfterSaleGetResponse
* @throws WxErrorException
*/
@Override
public WxMaShopEcAfterSaleGetResponse get(WxMaShopEcAfterSaleGetRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(ECAFTERSALE_GET, request);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopEcAfterSaleGetResponse.class);
}
/**
* 更新售后
*
* @param request
* @return
* @throws WxErrorException
*/
@Override
public WxMaShopBaseResponse update(WxMaShopAfterSaleUpdateRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(AFTERSALE_UPDATE, request);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopBaseResponse.class);
}
@Override
public WxMaShopBaseResponse update(WxMaShopEcAfterSaleUpdateRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(EC_AFTERSALE_UPDATE, request);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopBaseResponse.class);
}
/**
* 用户取消售后申请
* @param outAfterSaleId 商家自定义订单ID
* @param afterSaleId 与out_aftersale_id二选一
* @param openId 用户openid
* @return
* @throws WxErrorException
*/
@Override
public WxMaShopBaseResponse cancel(String outAfterSaleId, Long afterSaleId, String openId)
throws WxErrorException {
JsonObject request = GsonHelper.buildJsonObject("out_aftersale_id", outAfterSaleId,
"aftersale_id", afterSaleId, "openid", openId);
String resp = this.wxMaService.post(AFTERSALE_CANCEL, request);
JsonObject jsonObject = GsonParser.parse(resp);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(resp, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(resp, WxMaShopBaseResponse.class);
}
/**
* 用户上传退货物流
* @param request
* @return
* @throws WxErrorException
*/
@Override
public WxMaShopBaseResponse uploadReturnInfo(WxMaShopAfterSaleUploadReturnInfoRequest request)
throws WxErrorException {
String resp = this.wxMaService.post(AFTERSALE_UPLOAD_RETURN_INFO, request);
JsonObject jsonObject = GsonParser.parse(resp);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(resp, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(resp, WxMaShopBaseResponse.class);
}
/**
* 商家同意退款
* @param outAfterSaleId
* @param afterSaleId
* @return
* @throws WxErrorException
*/
@Override
public WxMaShopBaseResponse acceptRefund(String outAfterSaleId, Long afterSaleId)
throws WxErrorException {
JsonObject request = GsonHelper.buildJsonObject("out_aftersale_id", outAfterSaleId,
"aftersale_id", afterSaleId);
String resp = this.wxMaService.post(AFTERSALE_ACCEPT_REFUND, request);
JsonObject jsonObject = GsonParser.parse(resp);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(resp, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(resp, WxMaShopBaseResponse.class);
}
/**
* 商家同意退货
* @param request
* @return
* @throws WxErrorException
*/
@Override
public WxMaShopBaseResponse acceptReturn(WxMaShopAcceptReturnRequest request)
throws WxErrorException {
String resp = this.wxMaService.post(AFTERSALE_ACCEPT_RETURN, request);
JsonObject jsonObject = GsonParser.parse(resp);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(resp, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(resp, WxMaShopBaseResponse.class);
}
/**
* 商家拒绝售后
* @param outAfterSaleId
* @param afterSaleId
* @return
* @throws WxErrorException
*/
@Override
public WxMaShopBaseResponse reject(String outAfterSaleId, Long afterSaleId)
throws WxErrorException {
JsonObject request = GsonHelper.buildJsonObject("out_aftersale_id", outAfterSaleId,
"aftersale_id", afterSaleId);
String resp = this.wxMaService.post(AFTERSALE_REJECT, request);
JsonObject jsonObject = GsonParser.parse(resp);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(resp, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(resp, WxMaShopBaseResponse.class);
}
/**
* 商家上传退款凭证
* @param request
* @return
* @throws WxErrorException
*/
@Override
public WxMaShopBaseResponse uploadCertificates(WxMaShopUploadCerficatesRequest request)
throws WxErrorException {
String resp = this.wxMaService.post(AFTERSALE_UPLOAD_CERTIFICATES, request);
JsonObject jsonObject = GsonParser.parse(resp);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(resp, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(resp, WxMaShopBaseResponse.class);
}
/**
* 商家更新订单售后期
* @param outOrderId
* @param orderId
* @param openid
* @param afterSaleDeadline
* @return
* @throws WxErrorException
*/
@Override
public WxMaShopBaseResponse updateDeadline(String outOrderId, Long orderId, String openid,
Long afterSaleDeadline) throws WxErrorException {
JsonObject request = GsonHelper.buildJsonObject("out_order_id", outOrderId,
"order_id", orderId, "openid", openid, "after_sale_deadline", afterSaleDeadline);
String resp = this.wxMaService.post(AFTERSALE_UPLOAD_DEADLINE, request);
JsonObject jsonObject = GsonParser.parse(resp);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(resp, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(resp, WxMaShopBaseResponse.class);
}
/**
* 获取售后单详情
* @param request
* @return
* @throws WxErrorException
*/
@Override
public WxMaShopAfterSaleListResponse list(WxMaShopAfterSaleListRequest request) throws WxErrorException {
String resp = this.wxMaService.post(AFTERSALE_GET_LIST, request);
JsonObject jsonObject = GsonParser.parse(resp);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(resp, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(resp, WxMaShopAfterSaleListResponse.class);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaExpressDeliveryReturnServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaExpressDeliveryReturnServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaExpressDeliveryReturnService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.express.request.WxMaExpressDeliveryReturnAddRequest;
import cn.binarywang.wx.miniapp.bean.express.result.WxMaExpressReturnInfoResult;
import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
@RequiredArgsConstructor
public class WxMaExpressDeliveryReturnServiceImpl implements WxMaExpressDeliveryReturnService {
private final WxMaService service;
@Override
public WxMaExpressReturnInfoResult addDeliveryReturn(WxMaExpressDeliveryReturnAddRequest wxMaExpressDeliveryReturnAddRequest) throws WxErrorException {
String result = this.service.post(ADD_DELIVERY_RETURN_URL, wxMaExpressDeliveryReturnAddRequest.toJson());
return WxMaExpressReturnInfoResult.fromJson(result);
}
@Override
public WxMaExpressReturnInfoResult getDeliveryReturn(String returnId) throws WxErrorException {
JsonObject param = new JsonObject();
param.addProperty("return_id", returnId);
String result = this.service.post(GET_DELIVERY_RETURN_URL, param);
return WxMaExpressReturnInfoResult.fromJson(result);
}
@Override
public WxMaExpressReturnInfoResult unbindDeliveryReturn(String returnId) throws WxErrorException {
JsonObject param = new JsonObject();
param.addProperty("return_id", returnId);
String result = this.service.post(UNBIND_DELIVERY_RETURN_URL, param);
return WxMaExpressReturnInfoResult.fromJson(result);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopSharerServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopSharerServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Sharer;
import static me.chanjar.weixin.common.api.WxConsts.ERR_CODE;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.WxMaShopSharerService;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopSearchSharerResponse;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopSharerBindResponse;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopSharerDataSummaryResponse;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopSharerListResponse;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopSharerLiveOrderListResponse;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopSharerLiveSummaryListResponse;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopSharerUnbindResponse;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonHelper;
import me.chanjar.weixin.common.util.json.GsonParser;
/**
* @author leiin
* created on 2022/6/18 3:38 下午
*/
@RequiredArgsConstructor
@Slf4j
public class WxMaShopSharerServiceImpl implements WxMaShopSharerService {
private final WxMaService wxMaService;
@Override
public WxMaShopSharerBindResponse bindSharer(String[] openids) throws WxErrorException {
JsonObject json = GsonHelper.buildJsonObject("openids", openids);
String responseContent = this.wxMaService.post(Sharer.BIND, json);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopSharerBindResponse.class);
}
@Override
public WxMaShopSharerDataSummaryResponse getSharerDataSummary(String openid) throws WxErrorException {
JsonObject json = GsonHelper.buildJsonObject("openid", openid);
String responseContent = this.wxMaService.post(Sharer.GET_SHARER_DATA_SUMMARY, json);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopSharerDataSummaryResponse.class);
}
@Override
public WxMaShopSharerListResponse getSharerList(Integer page, Integer pageSize) throws WxErrorException {
JsonObject json = GsonHelper.buildJsonObject("page", page, "page_size", pageSize);
String responseContent = this.wxMaService.post(Sharer.GET_SHARER_LIST, json);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopSharerListResponse.class);
}
@Override
public WxMaShopSharerLiveOrderListResponse getSharerLiveOrderList(String openid, String liveExportId,
Integer page, Integer pageSize) throws WxErrorException {
JsonObject json = GsonHelper.buildJsonObject("openid", openid, "live_export_id", liveExportId,
"page", page, "page_size", pageSize);
String responseContent = this.wxMaService.post(Sharer.GET_SHARER_LIVE_ORDER_LIST, json);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopSharerLiveOrderListResponse.class);
}
@Override
public WxMaShopSharerLiveSummaryListResponse getSharerLiveSummaryList(String openid,
Integer page, Integer pageSize) throws WxErrorException {
JsonObject json = GsonHelper.buildJsonObject("openid", openid, "page", page, "page_size", pageSize);
String responseContent = this.wxMaService.post(Sharer.GET_SHARER_LIVE_SUMMARY_LIST, json);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopSharerLiveSummaryListResponse.class);
}
@Override
public WxMaShopSearchSharerResponse searchSharer(String openid) throws WxErrorException {
JsonObject json = GsonHelper.buildJsonObject("openid", openid);
String responseContent = this.wxMaService.post(Sharer.SEARCH_SHARER, json);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopSearchSharerResponse.class);
}
@Override
public WxMaShopSharerUnbindResponse unbindSharer(String[] openids) throws WxErrorException {
JsonObject json = GsonHelper.buildJsonObject("openids", openids);
String responseContent = this.wxMaService.post(Sharer.UNBIND, json);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopSharerUnbindResponse.class);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaPluginServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaPluginServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaPluginService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaPluginListResult;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.common.collect.ImmutableMap;
import lombok.AllArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import java.util.Map;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Plugin.PLUGIN_URL;
@AllArgsConstructor
public class WxMaPluginServiceImpl implements WxMaPluginService {
private final WxMaService service;
@Override
public void applyPlugin(String pluginAppId, String reason) throws WxErrorException {
Map<String, String> params = ImmutableMap.of("action", "apply",
"plugin_appid", pluginAppId,
"reason", reason);
this.service.post(PLUGIN_URL, WxMaGsonBuilder.create().toJson(params));
}
@Override
public WxMaPluginListResult getPluginList() throws WxErrorException {
Map<String, String> params = ImmutableMap.of("action", "list");
String responseContent = this.service.post(PLUGIN_URL, WxMaGsonBuilder.create().toJson(params));
return WxMaPluginListResult.fromJson(responseContent);
}
@Override
public void unbindPlugin(String pluginAppId) throws WxErrorException {
Map<String, String> params = ImmutableMap.of("action", "unbind", "plugin_appid", pluginAppId);
this.service.post(PLUGIN_URL, WxMaGsonBuilder.create().toJson(params));
}
@Override
public void updatePlugin(String pluginAppId, String userVersion) throws WxErrorException {
Map<String, String> params = ImmutableMap.of("action", "update",
"plugin_appid", pluginAppId,
"user_version", userVersion);
this.service.post(PLUGIN_URL, WxMaGsonBuilder.create().toJson(params));
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaRunServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaRunServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaRunService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaRunStepInfo;
import cn.binarywang.wx.miniapp.util.crypt.WxMaCryptUtils;
import lombok.RequiredArgsConstructor;
import java.util.List;
/**
* <pre>
* Created by Binary Wang on 2018/11/4.
* </pre>
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
@RequiredArgsConstructor
public class WxMaRunServiceImpl implements WxMaRunService {
private final WxMaService service;
@Override
public List<WxMaRunStepInfo> getRunStepInfo(String sessionKey, String encryptedData, String ivStr) {
return WxMaRunStepInfo.fromJson(WxMaCryptUtils.decrypt(sessionKey, encryptedData, ivStr));
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaProductServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaProductServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Product.OTHER.GET_BRAND;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Product.OTHER.GET_CATEGORY;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Product.OTHER.GET_FREIGHT_TEMPLATE;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Product.OTHER.IMG_UPLOAD;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Product.Sku.PRODUCT_SKU_LIST;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Product.Sku.PRODUCT_ADD_SKU_URL;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Product.Sku.PRODUCT_BATCH_ADD_SKU_URL;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Product.Sku.PRODUCT_DEL_SKU_URL;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Product.Sku.PRODUCT_UPDATE_SKU_PRICE_URL;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Product.Sku.PRODUCT_UPDATE_SKU_STOCK_URL;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Product.Sku.PRODUCT_UPDATE_SKU_URL;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Product.Spu.PRODUCT_SPU_ADD_URL;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Product.Spu.PRODUCT_SPU_DELISTING_URL;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Product.Spu.PRODUCT_SPU_DEL_URL;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Product.Spu.PRODUCT_SPU_GET_LIST_URL;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Product.Spu.PRODUCT_SPU_GET_URL;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Product.Spu.PRODUCT_SPU_LISTING_URL;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Product.Spu.PRODUCT_SPU_UPDATE_URL;
import static me.chanjar.weixin.common.api.WxConsts.ERR_CODE;
import cn.binarywang.wx.miniapp.api.WxMaProductService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.product.WxMinishopAddGoodsSkuData;
import cn.binarywang.wx.miniapp.bean.product.WxMinishopAddGoodsSpuData;
import cn.binarywang.wx.miniapp.bean.product.WxMinishopGetBrandResponse;
import cn.binarywang.wx.miniapp.bean.product.WxMinishopGetCategoryResponse;
import cn.binarywang.wx.miniapp.bean.product.WxMinishopGetFrightTemplateResponse;
import cn.binarywang.wx.miniapp.bean.product.WxMinishopResult;
import cn.binarywang.wx.miniapp.bean.product.WxMinishopSku;
import cn.binarywang.wx.miniapp.bean.product.WxMinishopSkuListResponse;
import cn.binarywang.wx.miniapp.bean.product.WxMinishopSpu;
import cn.binarywang.wx.miniapp.bean.product.WxMinishopSpuGetResponse;
import cn.binarywang.wx.miniapp.bean.product.WxMinishopSpuListResponse;
import cn.binarywang.wx.miniapp.bean.product.WxMinishopUpdateGoodsSkuData;
import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopSpuPageRequest;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopBaseResponse;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.bean.result.WxMinishopImageUploadResult;
import me.chanjar.weixin.common.util.http.MinishopUploadRequestExecutor;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonHelper;
import me.chanjar.weixin.common.util.json.GsonParser;
/**
* @author boris
*/
@RequiredArgsConstructor
@Slf4j
public class WxMaProductServiceImpl implements WxMaProductService {
private final WxMaService wxMaService;
@Override
public WxMinishopImageUploadResult uploadImg(File file, Integer respType, Integer width,
Integer height) throws WxErrorException {
String url = IMG_UPLOAD + "?upload_type=0" + "&height=" + height + "&width=" + width + "&resp_type=" + respType;
WxMinishopImageUploadResult result = this.wxMaService.execute(
MinishopUploadRequestExecutor.create(this.wxMaService.getRequestHttp()), url, file);
return result;
}
@Override
public WxMinishopImageUploadResult uploadImg(String imgUrl, Integer respType) throws WxErrorException {
JsonObject jsonObject = GsonHelper.buildJsonObject("img_url", imgUrl);
String url = IMG_UPLOAD + "?upload_type=1" + "&resp_type=" + respType;
String response = this.wxMaService.post(url, jsonObject);
JsonObject respObj = GsonParser.parse(response);
if (respObj.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(response, WxType.MiniApp));
}
return WxMinishopImageUploadResult.fromJson(response);
}
@Override
public WxMinishopGetCategoryResponse getCategory(Integer fCatId) throws WxErrorException {
JsonObject jsonObject = GsonHelper.buildJsonObject("f_cat_id", fCatId);
String response = this.wxMaService.post(GET_CATEGORY, jsonObject);
JsonObject respObj = GsonParser.parse(response);
if (respObj.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(response, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(response, WxMinishopGetCategoryResponse.class);
}
@Override
public WxMinishopGetBrandResponse getBrand() throws WxErrorException {
String response = this.wxMaService.post(GET_BRAND, new Object());
JsonObject respObj = GsonParser.parse(response);
if (respObj.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(response, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(response, WxMinishopGetBrandResponse.class);
}
@Override
public WxMinishopGetFrightTemplateResponse getFreightTemplate() throws WxErrorException {
String response = this.wxMaService.post(GET_FREIGHT_TEMPLATE, new Object());
JsonObject respObj = GsonParser.parse(response);
if (respObj.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(response, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(response, WxMinishopGetFrightTemplateResponse.class);
}
@Override
public WxMinishopResult<WxMinishopAddGoodsSpuData> addSpu(WxMinishopSpu spu) throws WxErrorException {
String response = this.wxMaService.post(PRODUCT_SPU_ADD_URL, spu);
JsonObject respObj = GsonParser.parse(response);
if (respObj.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(response, WxType.MiniApp));
}
WxMinishopResult<WxMinishopAddGoodsSpuData> result = new WxMinishopResult<>();
result.setErrcode(respObj.get(ERR_CODE).getAsInt());
JsonObject dataObj = respObj.get("data").getAsJsonObject();
WxMinishopAddGoodsSpuData resultData = new WxMinishopAddGoodsSpuData();
resultData.setProductId(dataObj.get("product_id").getAsLong());
resultData.setOutProductId(dataObj.get("out_product_id").getAsString());
resultData.setCreateTime(dataObj.get("create_time").getAsString());
result.setData(resultData);
return result;
}
@Override
public WxMaShopBaseResponse deleteSpu(Integer productId, String outProductId)
throws WxErrorException {
String responseContent = this.wxMaService
.post(PRODUCT_SPU_DEL_URL, GsonHelper.buildJsonObject("product_id", productId,
"out_product_id", outProductId));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopBaseResponse.class);
}
@Override
public WxMinishopSpuGetResponse getSpu(Integer productId, String outProductId, Integer needEditSpu)
throws WxErrorException {
String response = this.wxMaService
.post(PRODUCT_SPU_GET_URL, GsonHelper.buildJsonObject("product_id", productId,
"out_product_id", outProductId, "need_edit_spu", needEditSpu));
JsonObject jsonObject = GsonParser.parse(response);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(response, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(response, WxMinishopSpuGetResponse.class);
}
@Override
public WxMinishopSpuListResponse getSpuList(WxMaShopSpuPageRequest request)
throws WxErrorException {
String responseContent = this.wxMaService.post(PRODUCT_SPU_GET_LIST_URL, request);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMinishopSpuListResponse.class);
}
@Override
public WxMinishopResult<WxMinishopAddGoodsSpuData> updateSpu(WxMinishopSpu spu) throws WxErrorException {
String response = this.wxMaService.post(PRODUCT_SPU_UPDATE_URL, spu);
JsonObject respObj = GsonParser.parse(response);
if (respObj.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(response, WxType.MiniApp));
}
WxMinishopResult<WxMinishopAddGoodsSpuData> result = new WxMinishopResult<>();
result.setErrcode(respObj.get(ERR_CODE).getAsInt());
JsonObject dataObj = respObj.get("data").getAsJsonObject();
WxMinishopAddGoodsSpuData resultData = new WxMinishopAddGoodsSpuData();
resultData.setProductId(dataObj.get("product_id").getAsLong());
resultData.setOutProductId(dataObj.get("out_product_id").getAsString());
resultData.setUpdateTime(dataObj.get("update_time").getAsString());
result.setData(resultData);
return result;
}
@Override
public WxMaShopBaseResponse listingSpu(Integer productId, String outProductId)
throws WxErrorException {
String responseContent = this.wxMaService
.post(PRODUCT_SPU_LISTING_URL, GsonHelper.buildJsonObject("product_id", productId,
"out_product_id", outProductId));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopBaseResponse.class);
}
@Override
public WxMaShopBaseResponse delistingSpu(Integer productId, String outProductId)
throws WxErrorException {
String responseContent = this.wxMaService
.post(PRODUCT_SPU_DELISTING_URL, GsonHelper.buildJsonObject("product_id", productId,
"out_product_id", outProductId));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopBaseResponse.class);
}
@Override
public WxMinishopSkuListResponse getSkuList(Long productId, Integer needRealStock, Integer needEditSku)
throws WxErrorException {
String responseContent = this.wxMaService
.post(PRODUCT_SKU_LIST, GsonHelper.buildJsonObject("product_id", productId,
"need_edit_sku", needEditSku, "need_real_stock", needRealStock));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMinishopSkuListResponse.class);
}
@Override
public WxMinishopResult<WxMinishopAddGoodsSkuData> minishiopGoodsAddSku(
WxMinishopSku sku) throws WxErrorException {
String response = this.wxMaService
.post(PRODUCT_ADD_SKU_URL, sku);
JsonObject jsonObject = GsonParser.parse(response);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(response, WxType.MiniApp));
}
WxMinishopResult<WxMinishopAddGoodsSkuData> result = new WxMinishopResult<>();
result.setErrcode(jsonObject.get(ERR_CODE).getAsInt());
JsonObject dataObj = jsonObject.get("data").getAsJsonObject();
WxMinishopAddGoodsSkuData resultData = new WxMinishopAddGoodsSkuData();
resultData.setSkuId(dataObj.get("sku_id").getAsLong());
resultData.setCreateTime(dataObj.get("create_time").getAsString());
result.setData(resultData);
return result;
}
@Override
public WxMinishopResult<List<WxMinishopAddGoodsSkuData>> minishopGoodsBatchAddSku(
List<WxMinishopSku> skuList) throws WxErrorException {
String response = this.wxMaService
.post(PRODUCT_BATCH_ADD_SKU_URL, GsonHelper.buildJsonObject("skus", skuList));
JsonObject jsonObject = GsonParser.parse(response);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(response, WxType.MiniApp));
}
WxMinishopResult<List<WxMinishopAddGoodsSkuData>> result = new WxMinishopResult<>();
result.setErrcode(jsonObject.get(ERR_CODE).getAsInt());
JsonArray jsonArray = jsonObject.get("data").getAsJsonArray();
List<WxMinishopAddGoodsSkuData> skuData = new ArrayList<>();
for (JsonElement jsonElement : jsonArray) {
JsonObject element = jsonElement.getAsJsonObject();
WxMinishopAddGoodsSkuData resultData = new WxMinishopAddGoodsSkuData();
resultData.setSkuId(element.get("sku_id").getAsLong());
resultData.setOutSkuId(element.get("out_sku_id").getAsString());
resultData.setCreateTime(element.get("create_time").getAsString());
skuData.add(resultData);
}
result.setData(skuData);
return result;
}
@Override
public WxMaShopBaseResponse minishopGoodsDelSku(Long productId, Long outProductId,
String outSkuId, Long skuId) throws WxErrorException {
String response = this.wxMaService
.post(PRODUCT_DEL_SKU_URL, GsonHelper.buildJsonObject("product_id", productId,
"out_product_id", outProductId, "out_sku_id", outSkuId, "sku_id", skuId));
JsonObject jsonObject = GsonParser.parse(response);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(response, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(response, WxMaShopBaseResponse.class);
}
@Override
public WxMinishopResult<WxMinishopUpdateGoodsSkuData> minishopGoodsUpdateSku(
WxMinishopSku sku) throws WxErrorException {
String response = this.wxMaService
.post(PRODUCT_UPDATE_SKU_URL, sku);
JsonObject jsonObject = GsonParser.parse(response);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(response, WxType.MiniApp));
}
WxMinishopResult<WxMinishopUpdateGoodsSkuData> result = new WxMinishopResult<>();
result.setErrcode(jsonObject.get(ERR_CODE).getAsInt());
JsonObject dataObj = jsonObject.get("data").getAsJsonObject();
WxMinishopUpdateGoodsSkuData resultData = new WxMinishopUpdateGoodsSkuData();
resultData.setUpdateTime(dataObj.get("update_time").getAsString());
result.setData(resultData);
return result;
}
@Override
public WxMinishopResult<WxMinishopUpdateGoodsSkuData> minishopGoodsUpdateSkuPrice(
Long productId, String outProductId, String outSkuId, Long skuId, Long salePrice,
Long marketPrice) throws WxErrorException {
String response = this.wxMaService
.post(PRODUCT_UPDATE_SKU_PRICE_URL, GsonHelper.buildJsonObject(
"product_id", productId, "out_product_id", outProductId,
"sku_id", skuId, "out_sku_id", outSkuId, "sale_price", salePrice, "market_price", marketPrice));
JsonObject jsonObject = GsonParser.parse(response);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(response, WxType.MiniApp));
}
WxMinishopResult<WxMinishopUpdateGoodsSkuData> result = new WxMinishopResult<>();
result.setErrcode(jsonObject.get(ERR_CODE).getAsInt());
JsonObject dataObj = jsonObject.get("data").getAsJsonObject();
WxMinishopUpdateGoodsSkuData resultData = new WxMinishopUpdateGoodsSkuData();
resultData.setUpdateTime(dataObj.get("update_time").getAsString());
result.setData(resultData);
return result;
}
@Override
public WxMinishopResult<WxMinishopUpdateGoodsSkuData> minishopGoodsUpdateSkuStock(
Long productId, String outProductId, String outSkuId, Long skuId, Integer type,
Integer stockNum) throws WxErrorException {
String response = this.wxMaService
.post(PRODUCT_UPDATE_SKU_STOCK_URL, GsonHelper.buildJsonObject(
"product_id", productId, "out_product_id", outProductId,
"sku_id", skuId, "out_sku_id", outSkuId, "type", type, "stock_num", stockNum));
JsonObject jsonObject = GsonParser.parse(response);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(response, WxType.MiniApp));
}
WxMinishopResult<WxMinishopUpdateGoodsSkuData> result = new WxMinishopResult<>();
result.setErrcode(jsonObject.get(ERR_CODE).getAsInt());
JsonObject dataObj = jsonObject.get("data").getAsJsonObject();
WxMinishopUpdateGoodsSkuData resultData = new WxMinishopUpdateGoodsSkuData();
resultData.setUpdateTime(dataObj.get("update_time").getAsString());
result.setData(resultData);
return result;
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaQrcodeServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaQrcodeServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaQrcodeService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaCodeLineColor;
import cn.binarywang.wx.miniapp.bean.WxMaQrcode;
import cn.binarywang.wx.miniapp.bean.WxaCode;
import cn.binarywang.wx.miniapp.bean.WxaCodeUnlimit;
import cn.binarywang.wx.miniapp.executor.QrcodeBytesRequestExecutor;
import cn.binarywang.wx.miniapp.executor.QrcodeRequestExecutor;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import org.apache.commons.lang3.StringUtils;
import java.io.File;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Qrcode.*;
import static cn.binarywang.wx.miniapp.constant.WxMaConstants.DEFAULT_ENV_VERSION;
/**
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
@RequiredArgsConstructor
public class WxMaQrcodeServiceImpl implements WxMaQrcodeService {
private final WxMaService service;
@Override
public byte[] createQrcodeBytes(String path, int width) throws WxErrorException {
return this.service.execute(QrcodeBytesRequestExecutor.create(this.service.getRequestHttp()), CREATE_QRCODE_URL,
new WxMaQrcode(path, width));
}
@Override
public File createQrcode(String path, int width) throws WxErrorException {
return this.service.execute(QrcodeRequestExecutor.create(this.service.getRequestHttp()), CREATE_QRCODE_URL,
new WxMaQrcode(path, width));
}
@Override
public File createQrcode(String path) throws WxErrorException {
return this.createQrcode(path, 430);
}
@Override
public byte[] createWxaCodeBytes(String path, String envVersion, int width, boolean autoColor,
WxMaCodeLineColor lineColor, boolean isHyaline) throws WxErrorException {
return this.service.execute(QrcodeBytesRequestExecutor.create(this.service.getRequestHttp()), GET_WXACODE_URL,
WxaCode.builder()
.path(path)
.envVersion(StringUtils.defaultIfEmpty(envVersion, DEFAULT_ENV_VERSION))
.width(width)
.autoColor(autoColor)
.lineColor(lineColor)
.isHyaline(isHyaline)
.build());
}
@Override
public File createWxaCode(String path, String envVersion, int width, boolean autoColor, WxMaCodeLineColor lineColor,
boolean isHyaline) throws WxErrorException {
return this.service.execute(QrcodeRequestExecutor.create(this.service.getRequestHttp()), GET_WXACODE_URL,
WxaCode.builder()
.path(path)
.envVersion(StringUtils.defaultIfEmpty(envVersion, DEFAULT_ENV_VERSION))
.width(width)
.autoColor(autoColor)
.lineColor(lineColor)
.isHyaline(isHyaline)
.build());
}
@Override
public File createWxaCode(String path, int width) throws WxErrorException {
return this.createWxaCode(path, null, width, true, null, false);
}
@Override
public File createWxaCode(String path) throws WxErrorException {
return this.createWxaCode(path, 430);
}
@Override
public byte[] createWxaCodeUnlimitBytes(String scene, String page, boolean checkPath, String envVersion, int width,
boolean autoColor, WxMaCodeLineColor lineColor, boolean isHyaline)
throws WxErrorException {
return this.service.execute(QrcodeBytesRequestExecutor.create(this.service.getRequestHttp()),
GET_WXACODE_UNLIMIT_URL, this.buildWxaCodeUnlimit(scene, page, checkPath, envVersion, width, autoColor, lineColor, isHyaline));
}
@Override
public File createWxaCodeUnlimit(String scene, String page, boolean checkPath, String envVersion, int width,
boolean autoColor, WxMaCodeLineColor lineColor, boolean isHyaline) throws WxErrorException {
return this.service.execute(QrcodeRequestExecutor.create(this.service.getRequestHttp()),
GET_WXACODE_UNLIMIT_URL, this.buildWxaCodeUnlimit(scene, page, checkPath, envVersion, width, autoColor, lineColor, isHyaline));
}
private WxaCodeUnlimit buildWxaCodeUnlimit(String scene, String page, boolean checkPath, String envVersion, int width,
boolean autoColor, WxMaCodeLineColor lineColor, boolean isHyaline) {
WxaCodeUnlimit wxaCodeUnlimit = new WxaCodeUnlimit();
wxaCodeUnlimit.setScene(scene);
wxaCodeUnlimit.setPage(page);
wxaCodeUnlimit.setCheckPath(checkPath);
wxaCodeUnlimit.setEnvVersion(envVersion);
wxaCodeUnlimit.setWidth(width);
wxaCodeUnlimit.setAutoColor(autoColor);
wxaCodeUnlimit.setLineColor(lineColor);
wxaCodeUnlimit.setHyaline(isHyaline);
return wxaCodeUnlimit;
}
@Override
public File createWxaCodeUnlimit(String scene, String page) throws WxErrorException {
return this.createWxaCodeUnlimit(scene, page, true, DEFAULT_ENV_VERSION, 430, true, null, false);
}
@Override
public File createQrcode(String path, int width, String filePath) throws WxErrorException {
return this.service.execute(QrcodeRequestExecutor.create(this.service.getRequestHttp(), filePath),
CREATE_QRCODE_URL, new WxMaQrcode(path, width));
}
@Override
public File createQrcode(String path, String filePath) throws WxErrorException {
return createQrcode(path, 430, filePath);
}
@Override
public File createWxaCode(String path, String envVersion, int width, String filePath, boolean autoColor,
WxMaCodeLineColor lineColor, boolean isHyaline) throws WxErrorException {
return this.service.execute(QrcodeRequestExecutor.create(this.service.getRequestHttp(), filePath), GET_WXACODE_URL,
WxaCode.builder()
.path(path)
.envVersion(StringUtils.defaultIfEmpty(envVersion, DEFAULT_ENV_VERSION))
.width(width)
.autoColor(autoColor)
.lineColor(lineColor)
.isHyaline(isHyaline)
.build());
}
@Override
public File createWxaCode(String path, int width, String filePath) throws WxErrorException {
return this.createWxaCode(path, null, width, filePath, true, null, false);
}
@Override
public File createWxaCode(String path, String filePath) throws WxErrorException {
return this.createWxaCode(path, 430, filePath);
}
@Override
public File createWxaCodeUnlimit(String scene, String page, String filePath, boolean checkPath, String envVersion,
int width, boolean autoColor, WxMaCodeLineColor lineColor, boolean isHyaline)
throws WxErrorException {
return this.service.execute(QrcodeRequestExecutor.create(this.service.getRequestHttp(), filePath),
GET_WXACODE_UNLIMIT_URL, this.buildWxaCodeUnlimit(scene, page, checkPath, envVersion, width, autoColor, lineColor, isHyaline));
}
@Override
public File createWxaCodeUnlimit(String scene, String page, String filePath) throws WxErrorException {
return this.createWxaCodeUnlimit(scene, page, filePath, true, DEFAULT_ENV_VERSION, 430, true, null, false);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaOrderShippingServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaOrderShippingServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaOrderShippingService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.shop.request.WxMaOrderShippingIsTradeManagedRequest;
import cn.binarywang.wx.miniapp.bean.shop.request.shipping.*;
import cn.binarywang.wx.miniapp.bean.shop.response.*;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonHelper;
import me.chanjar.weixin.common.util.json.GsonParser;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.OrderShipping.*;
/**
* @author xzh
* created on 2023/5/17 17:44
*/
@Slf4j
@RequiredArgsConstructor
public class WxMaOrderShippingServiceImpl implements WxMaOrderShippingService {
private final WxMaService wxMaService;
/**
* 查询小程序是否已开通发货信息管理服务
*
* @param appId 待查询小程序的 appid,非服务商调用时仅能查询本账号
* @return WxMaOrderShippingInfoBaseResponse
* @throws WxErrorException e
*/
@Override
public WxMaOrderShippingIsTradeManagedResponse isTradeManaged(String appId) throws WxErrorException {
WxMaOrderShippingIsTradeManagedRequest request = WxMaOrderShippingIsTradeManagedRequest.builder().appId(appId).build();
return request(IS_TRADE_MANAGED, request, WxMaOrderShippingIsTradeManagedResponse.class);
}
/**
* 发货信息录入接口
*
* @param request 请求
* @return WxMaOrderShippingInfoBaseResponse
* @throws WxErrorException e
*/
@Override
public WxMaOrderShippingInfoBaseResponse upload(WxMaOrderShippingInfoUploadRequest request) throws WxErrorException {
return request(UPLOAD_SHIPPING_INFO, request, WxMaOrderShippingInfoBaseResponse.class);
}
/**
* 发货信息合单录入接口
*
* @param request 请求
* @return WxMaOrderShippingInfoBaseResponse
* @throws WxErrorException e
*/
@Override
public WxMaOrderShippingInfoBaseResponse upload(WxMaOrderCombinedShippingInfoUploadRequest request) throws WxErrorException {
return request(UPLOAD_COMBINED_SHIPPING_INFO, request, WxMaOrderShippingInfoBaseResponse.class);
}
/**
* 查询订单发货状态
* 你可以通过交易单号或商户号+商户单号来查询该支付单的发货状态。
*
* @param request 请求
* @return WxMaOrderShippingInfoGetResponse
* @throws WxErrorException e
*/
@Override
public WxMaOrderShippingInfoGetResponse get(WxMaOrderShippingInfoGetRequest request) throws WxErrorException {
return request(GET_SHIPPING_INFO, request, WxMaOrderShippingInfoGetResponse.class);
}
/**
* 查询订单列表
* 你可以通过支付时间、支付者openid或订单状态来查询订单列表。
*
* @param request 请求
* @return WxMaOrderShippingInfoGetListResponse
* @throws WxErrorException e
*/
@Override
public WxMaOrderShippingInfoGetListResponse getList(WxMaOrderShippingInfoGetListRequest request) throws WxErrorException {
return request(GET_SHIPPING_INFO_LIST, request, WxMaOrderShippingInfoGetListResponse.class);
}
/**
* 确认收货提醒接口
* 如你已经从你的快递物流服务方获知到用户已经签收相关商品,可以通过该接口提醒用户及时确认收货,以提高资金结算效率,每个订单仅可调用一次。
*
* @param request 请求
* @return WxMaOrderShippingInfoBaseResponse
* @throws WxErrorException e
*/
@Override
public WxMaOrderShippingInfoBaseResponse notifyConfirmReceive(WxMaOrderShippingInfoNotifyConfirmRequest request) throws WxErrorException {
return request(NOTIFY_CONFIRM_RECEIVE, request, WxMaOrderShippingInfoBaseResponse.class);
}
/**
* 消息跳转路径设置接口
* 如你已经在小程序内接入平台提供的确认收货组件,可以通过该接口设置发货消息及确认收货消息的跳转动作,用户点击发货消息时会直接进入你的小程序订单列表页面或详情页面进行确认收货,进一步优化用户体验。
*
* @param path 商户自定义跳转路径
* @return WxMaOrderShippingInfoBaseResponse
* @throws WxErrorException e
*/
@Override
public WxMaOrderShippingInfoBaseResponse setMsgJumpPath(String path) throws WxErrorException {
JsonObject jsonObject = GsonHelper.buildJsonObject("path", path);
return request(SET_MSG_JUMP_PATH, jsonObject, WxMaOrderShippingInfoBaseResponse.class);
}
/**
* 查询小程序是否已完成交易结算管理确认
*
* @param appId 待查询小程序的 appid,非服务商调用时仅能查询本账号
* @return WxMaOrderShippingITMCCompletedResult
* @throws WxErrorException e
*/
@Override
public WxMaOrderShippingITMCCompletedResult isTradeManagementConfirmationCompleted(String appId) throws WxErrorException {
JsonObject jsonObject = GsonHelper.buildJsonObject("appid", appId);
return request(IS_TRADE_MANAGEMENT_CONFIRMATION_COMPLETED, jsonObject, WxMaOrderShippingITMCCompletedResult.class);
}
/**
* 特殊发货报备
*
* @param orderId 需要特殊发货报备的订单号,可传入微信支付单号或商户单号
* @param type 特殊发货报备类型,1为预售商品订单,2为测试订单
* @param delayTo 预计发货时间的unix时间戳,type为1时必填,type为2可省略
* @return WxMaOrderShippingInfoBaseResponse
* @throws WxErrorException e
*/
@Override
public WxMaOrderShippingInfoBaseResponse opSpecialOrder(String orderId, Integer type, Long delayTo) throws WxErrorException {
JsonObject jsonObject = GsonHelper.buildJsonObject("order_id", orderId, "type", type, "delay_to", delayTo);
return request(OP_SPECIAL_ORDER, jsonObject, WxMaOrderShippingInfoBaseResponse.class);
}
private <T> T request(String url, Object request, Class<T> resultT) throws WxErrorException {
String responseContent = this.wxMaService.post(url, request);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, resultT);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopAccountServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopAccountServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.WxMaShopAccountService;
import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopAccountUpdateInfoRequest;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopAccountGetBrandListResponse;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopAccountGetCategoryListResponse;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopAccountGetInfoResponse;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopBaseResponse;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Account.*;
/**
* @author liming1019
*/
@RequiredArgsConstructor
@Slf4j
public class WxMaShopAccountServiceImpl implements WxMaShopAccountService {
private final WxMaService wxMaService;
@Override
public WxMaShopAccountGetCategoryListResponse getCategoryList() throws WxErrorException {
String responseContent = this.wxMaService.post(GET_CATEGORY_LIST, new JsonObject());
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopAccountGetCategoryListResponse.class);
}
@Override
public WxMaShopAccountGetBrandListResponse getBrandList() throws WxErrorException {
String responseContent = this.wxMaService.post(GET_BRAND_LIST, new JsonObject());
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopAccountGetBrandListResponse.class);
}
@Override
public WxMaShopBaseResponse updateInfo(WxMaShopAccountUpdateInfoRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(UPDATE_INFO, request);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopBaseResponse.class);
}
@Override
public WxMaShopAccountGetInfoResponse getInfo() throws WxErrorException {
String responseContent = this.wxMaService.post(GET_INFO, new JsonObject());
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopAccountGetInfoResponse.class);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/BaseWxMaServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/BaseWxMaServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.*;
import cn.binarywang.wx.miniapp.bean.WxMaApiResponse;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import cn.binarywang.wx.miniapp.config.WxMaConfig;
import cn.binarywang.wx.miniapp.executor.ApiSignaturePostRequestExecutor;
import cn.binarywang.wx.miniapp.util.WxMaConfigHolder;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.KeyFactory;
import java.security.SecureRandom;
import java.security.Signature;
import java.security.interfaces.RSAPrivateKey;
import java.security.spec.MGF1ParameterSpec;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.PSSParameterSpec;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.function.Function;
import javax.crypto.Cipher;
import javax.crypto.spec.GCMParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.bean.CommonUploadParam;
import me.chanjar.weixin.common.bean.ToJson;
import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.error.WxMaErrorMsgEnum;
import me.chanjar.weixin.common.error.WxRuntimeException;
import me.chanjar.weixin.common.executor.CommonUploadRequestExecutor;
import me.chanjar.weixin.common.service.WxImgProcService;
import me.chanjar.weixin.common.service.WxOcrService;
import me.chanjar.weixin.common.util.DataUtils;
import me.chanjar.weixin.common.util.crypto.SHA1;
import me.chanjar.weixin.common.util.http.*;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import org.apache.commons.lang3.StringUtils;
/**
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* @see #doGetAccessTokenRequest
*/
@Slf4j
public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestHttp<H, P> {
/**
* 开启API签名验证后需要API签名的接口,根据 https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/
* 整理,uri包含下这些字符串且配置了api signature aes ras key 自动用签名接口
*/
protected static final String[] urlPathSupportApiSignature =
new String[] {
"cgi-bin/clear_quota",
"cgi-bin/openapi/quota/get",
"cgi-bin/openapi/rid/get",
"wxa/getpluginopenpid",
"wxa/business/checkencryptedmsg",
"wxa/business/getuserencryptkey",
"wxa/business/getuserphonenumber",
"wxa/getwxacode",
"wxa/getwxacodeunlimit",
"cgi-bin/wxaapp/createwxaqrcode",
"cgi-bin/message/custom/send",
"cgi-bin/message/wxopen/updatablemsg/send",
"wxaapi/newtmpl/deltemplate",
"cgi-bin/message/subscribe/send",
"wxaapi/newtmpl/addtemplate",
"wxa/msg_sec_check",
"wxa/media_check_async",
"wxa/getuserriskrank",
"datacube/getweanalysisappidweeklyretaininfo",
"datacube/getweanalysisappidmonthlyretaininfo",
"datacube/getweanalysisappiddailyretaininfo",
"datacube/getweanalysisappidmonthlyvisittrend",
"datacube/getweanalysisappiddailyvisittrend",
"datacube/getweanalysisappidweeklyvisittrend",
"datacube/getweanalysisappiddailysummarytrend",
"datacube/getweanalysisappidvisitpage",
"datacube/getweanalysisappiduserportrait",
"wxa/business/performance/boot",
"datacube/getweanalysisappidvisitdistribution",
"wxa/getwxadevinfo",
"wxaapi/log/get_performance",
"wxaapi/log/jserr_detail",
"wxaapi/log/jserr_list",
"wxa/devplugin",
"wxa/plugin",
"cgi-bin/express/business/account/getall",
"cgi-bin/express/business/delivery/getall",
"cgi-bin/express/business/printer/getall",
"wxa/servicemarket",
"cgi-bin/soter/verify_signature"
};
protected static final Gson GSON = new Gson();
private final WxMaMsgService kefuService = new WxMaMsgServiceImpl(this);
private final WxMaMediaService materialService = new WxMaMediaServiceImpl(this);
private final WxMaUserService userService = new WxMaUserServiceImpl(this);
private final WxMaQrcodeService qrCodeService = new WxMaQrcodeServiceImpl(this);
private final WxMaSchemeService schemeService = new WxMaSchemeServiceImpl(this);
private final WxMaAnalysisService analysisService = new WxMaAnalysisServiceImpl(this);
private final WxMaCodeService codeService = new WxMaCodeServiceImpl(this);
private final WxMaCustomserviceWorkService customserviceWorkService = new WxMaCustomserviceWorkServiceImpl(this);
private final WxMaKefuService maKefuService = new WxMaKefuServiceImpl(this);
private final WxMaInternetService internetService = new WxMaInternetServiceImpl(this);
private final WxMaSettingService settingService = new WxMaSettingServiceImpl(this);
private final WxMaJsapiService jsapiService = new WxMaJsapiServiceImpl(this);
private final WxMaShareService shareService = new WxMaShareServiceImpl(this);
private final WxMaRunService runService = new WxMaRunServiceImpl(this);
private final WxMaSecurityService securityService = new WxMaSecurityServiceImpl(this);
private final WxMaPluginService pluginService = new WxMaPluginServiceImpl(this);
private final WxMaExpressService expressService = new WxMaExpressServiceImpl(this);
private final WxMaSubscribeService subscribeService = new WxMaSubscribeServiceImpl(this);
private final WxMaCloudService cloudService = new WxMaCloudServiceImpl(this);
private final WxMaLiveService liveService = new WxMaLiveServiceImpl(this);
private final WxMaLiveGoodsService liveGoodsService = new WxMaLiveGoodsServiceImpl(this);
private final WxMaLiveMemberService liveMemberService = new WxMaLiveMemberServiceImpl(this);
private final WxOcrService ocrService = new WxMaOcrServiceImpl(this);
private final WxImgProcService imgProcService = new WxMaImgProcServiceImpl(this);
private final WxMaShopSpuService shopSpuService = new WxMaShopSpuServiceImpl(this);
private final WxMaShopOrderService shopOrderService = new WxMaShopOrderServiceImpl(this);
private final WxMaShopRegisterService shopRegisterService = new WxMaShopRegisterServiceImpl(this);
private final WxMaShopAccountService shopAccountService = new WxMaShopAccountServiceImpl(this);
private final WxMaShopCatService shopCatService = new WxMaShopCatServiceImpl(this);
private final WxMaShopImgService shopImgService = new WxMaShopImgServiceImpl(this);
private final WxMaShopAuditService shopAuditService = new WxMaShopAuditServiceImpl(this);
private final WxMaShopAfterSaleService shopAfterSaleService =
new WxMaShopAfterSaleServiceImpl(this);
private final WxMaShopDeliveryService shopDeliveryService = new WxMaShopDeliveryServiceImpl(this);
private final WxMaLinkService linkService = new WxMaLinkServiceImpl(this);
private final WxMaReimburseInvoiceService reimburseInvoiceService =
new WxMaReimburseInvoiceServiceImpl(this);
private final WxMaDeviceSubscribeService deviceSubscribeService =
new WxMaDeviceSubscribeServiceImpl(this);
private final WxMaMarketingService marketingService = new WxMaMarketingServiceImpl(this);
private final WxMaImmediateDeliveryService immediateDeliveryService =
new WxMaImmediateDeliveryServiceImpl(this);
private final WxMaShopSharerService shopSharerService = new WxMaShopSharerServiceImpl(this);
private final WxMaProductService productService = new WxMaProductServiceImpl(this);
private final WxMaProductOrderService productOrderService = new WxMaProductOrderServiceImpl(this);
private final WxMaShopCouponService wxMaShopCouponService = new WxMaShopCouponServiceImpl(this);
private final WxMaShopPayService wxMaShopPayService = new WxMaShopPayServiceImpl(this);
private final WxMaOrderShippingService wxMaOrderShippingService =
new WxMaOrderShippingServiceImpl(this);
private final WxMaOrderManagementService wxMaOrderManagementService =
new WxMaOrderManagementServiceImpl(this);
private final WxMaOpenApiService wxMaOpenApiService = new WxMaOpenApiServiceImpl(this);
private final WxMaVodService wxMaVodService = new WxMaVodServiceImpl(this);
private final WxMaXPayService wxMaXPayService = new WxMaXPayServiceImpl(this);
private final WxMaExpressDeliveryReturnService wxMaExpressDeliveryReturnService =
new WxMaExpressDeliveryReturnServiceImpl(this);
private final WxMaPromotionService wxMaPromotionService = new WxMaPromotionServiceImpl(this);
private final WxMaIntracityService intracityService = new WxMaIntracityServiceImpl(this);
private final WxMaComplaintService complaintService = new WxMaComplaintServiceImpl(this);
private final WxMaEmployeeRelationService employeeRelationService =
new WxMaEmployeeRelationServiceImpl(this);
private Map<String, WxMaConfig> configMap = new HashMap<>();
private int retrySleepMillis = 1000;
private int maxRetryTimes = 5;
@Override
public RequestHttp<H, P> getRequestHttp() {
return this;
}
@Override
public String getPaidUnionId(String openid, String transactionId, String mchId, String outTradeNo)
throws WxErrorException {
Map<String, String> params = new HashMap<>(8);
params.put("openid", openid);
if (StringUtils.isNotEmpty(transactionId)) {
params.put("transaction_id", transactionId);
}
if (StringUtils.isNotEmpty(mchId)) {
params.put("mch_id", mchId);
}
if (StringUtils.isNotEmpty(outTradeNo)) {
params.put("out_trade_no", outTradeNo);
}
String responseContent =
this.get(GET_PAID_UNION_ID_URL, Joiner.on("&").withKeyValueSeparator("=").join(params));
WxError error = WxError.fromJson(responseContent, WxType.MiniApp);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
}
return GsonParser.parse(responseContent).get("unionid").getAsString();
}
@Override
public WxMaJscode2SessionResult jsCode2SessionInfo(String jsCode) throws WxErrorException {
final WxMaConfig config = getWxMaConfig();
Map<String, String> params = new HashMap<>(8);
params.put("appid", config.getAppid());
params.put("secret", config.getSecret());
params.put("js_code", jsCode);
params.put("grant_type", "authorization_code");
String result =
get(JSCODE_TO_SESSION_URL, Joiner.on("&").withKeyValueSeparator("=").join(params));
return WxMaJscode2SessionResult.fromJson(result);
}
@Override
public void setDynamicData(int lifespan, String type, int scene, String data)
throws WxErrorException {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("lifespan", lifespan);
jsonObject.addProperty("query", WxGsonBuilder.create().toJson(ImmutableMap.of("type", type)));
jsonObject.addProperty("data", data);
jsonObject.addProperty("scene", scene);
this.post(SET_DYNAMIC_DATA_URL, jsonObject.toString());
}
@Override
public boolean checkSignature(String timestamp, String nonce, String signature) {
try {
return SHA1.gen(this.getWxMaConfig().getToken(), timestamp, nonce).equals(signature);
} catch (Exception e) {
log.error("Checking signature failed, and the reason is :{}", e.getMessage());
return false;
}
}
@Override
public String getAccessToken() throws WxErrorException {
return getAccessToken(false);
}
@Override
public String getAccessToken(boolean forceRefresh) throws WxErrorException {
if (!forceRefresh && !this.getWxMaConfig().isAccessTokenExpired()) {
return this.getWxMaConfig().getAccessToken();
}
Lock lock = this.getWxMaConfig().getAccessTokenLock();
boolean locked = false;
try {
do {
locked = lock.tryLock(100, TimeUnit.MILLISECONDS);
if (!forceRefresh && !this.getWxMaConfig().isAccessTokenExpired()) {
return this.getWxMaConfig().getAccessToken();
}
} while (!locked);
String response;
if (getWxMaConfig().isStableAccessToken()) {
response = doGetStableAccessTokenRequest(forceRefresh);
} else {
response = doGetAccessTokenRequest();
}
return extractAccessToken(response);
} catch (IOException | InterruptedException e) {
throw new WxRuntimeException(e);
} finally {
if (locked) {
lock.unlock();
}
}
}
/**
* 通过网络请求获取AccessToken
*
* @return .
* @throws IOException .
*/
protected abstract String doGetAccessTokenRequest() throws IOException;
/**
* 通过网络请求获取稳定版接口调用凭据
*
* @return .
* @throws IOException .
*/
protected abstract String doGetStableAccessTokenRequest(boolean forceRefresh) throws IOException;
@Override
public String get(String url, String queryParam) throws WxErrorException {
return execute(SimpleGetRequestExecutor.create(this), url, queryParam);
}
private boolean isApiSignatureRequired(String url) {
return this.getWxMaConfig().getApiSignatureAesKey() != null
&& Arrays.stream(urlPathSupportApiSignature).anyMatch(url::contains);
}
@Override
public String post(String url, String postData) throws WxErrorException {
if (isApiSignatureRequired(url)) {
// 接口需要签名
log.debug("已经配置接口需要签名,接口{}将走加密访问路径", url);
JsonObject jsonObject = GSON.fromJson(postData == null ? "{}" : postData, JsonObject.class);
return postWithSignature(url, jsonObject);
} else {
return execute(SimplePostRequestExecutor.create(this), url, postData);
}
}
@Override
public String post(String url, Object obj) throws WxErrorException {
if (isApiSignatureRequired(url)) {
// 接口需要签名
log.debug("已经配置接口需要签名,接口{}将走加密访问路径", url);
return postWithSignature(url, obj);
} else {
return this.execute(
SimplePostRequestExecutor.create(this), url, WxGsonBuilder.create().toJson(obj));
}
}
@Override
public String post(String url, ToJson obj) throws WxErrorException {
return this.post(url, obj == null ? "{}" : obj.toJson());
}
@Override
public String post(String url, JsonObject jsonObject) throws WxErrorException {
return this.post(url, jsonObject == null ? "{}" : jsonObject.toString());
}
@Override
public String upload(String url, CommonUploadParam param) throws WxErrorException {
RequestExecutor<String, CommonUploadParam> executor =
CommonUploadRequestExecutor.create(getRequestHttp());
return this.execute(executor, url, param);
}
/** 向微信端发送请求,在这里执行的策略是当发生access_token过期时才去刷新,然后重新执行请求,而不是全局定时请求 */
@Override
public <R, T> R execute(RequestExecutor<R, T> executor, String uri, T data)
throws WxErrorException {
String dataForLog;
if (data == null) {
dataForLog = null;
} else if (data instanceof String) {
dataForLog = DataUtils.handleDataWithSecret((String) data);
} else {
dataForLog = data.toString();
}
return executeWithRetry(
(uriWithAccessToken) -> executor.execute(uriWithAccessToken, data, WxType.MiniApp),
uri,
dataForLog);
}
@Override
public WxMaApiResponse execute(
ApiSignaturePostRequestExecutor<?, ?> executor,
String uri,
Map<String, String> headers,
String data)
throws WxErrorException {
String dataForLog = "Headers: " + headers.toString() + " Body: " + data;
return executeWithRetry(
(uriWithAccessToken) -> executor.execute(uriWithAccessToken, headers, data, WxType.MiniApp),
uri,
dataForLog);
}
private static interface ExecutorAction<R> {
R execute(String urlWithAccessToken) throws IOException, WxErrorException;
}
private <R, T> R executeWithRetry(ExecutorAction<R> executor, String uri, String dataForLog)
throws WxErrorException {
int retryTimes = 0;
do {
try {
return this.executeInternal(executor, uri, dataForLog, false);
} catch (WxErrorException e) {
if (retryTimes + 1 > this.maxRetryTimes) {
log.warn("重试达到最大次数【{}】", maxRetryTimes);
// 最后一次重试失败后,直接抛出异常,不再等待
throw new WxErrorException(
WxError.builder()
.errorCode(e.getError().getErrorCode())
.errorMsg("微信服务端异常,超出重试次数!")
.build());
}
WxError error = e.getError();
// -1 系统繁忙, 1000ms后重试
if (error.getErrorCode() == -1) {
int sleepMillis = this.retrySleepMillis * (1 << retryTimes);
try {
log.warn("微信系统繁忙,{} ms 后重试(第{}次)", sleepMillis, retryTimes + 1);
Thread.sleep(sleepMillis);
} catch (InterruptedException e1) {
Thread.currentThread().interrupt();
}
} else {
throw e;
}
}
} while (retryTimes++ < this.maxRetryTimes);
log.warn("重试达到最大次数【{}】", this.maxRetryTimes);
throw new WxRuntimeException("微信服务端异常,超出重试次数");
}
private <R, T> R executeInternal(
ExecutorAction<R> executor, String uri, String dataForLog, boolean doNotAutoRefreshToken)
throws WxErrorException {
if (uri.contains("access_token=")) {
throw new IllegalArgumentException("uri参数中不允许有access_token: " + uri);
}
String accessToken = getAccessToken(false);
String effectiveApiHostUrl = this.getWxMaConfig().getEffectiveApiHostUrl();
if (!WxMaConfig.DEFAULT_API_HOST_URL.equals(effectiveApiHostUrl)) {
uri = uri.replace(WxMaConfig.DEFAULT_API_HOST_URL, effectiveApiHostUrl);
}
String uriWithAccessToken =
uri + (uri.contains("?") ? "&" : "?") + "access_token=" + accessToken;
try {
R result = executor.execute(uriWithAccessToken);
log.debug("\n【请求地址】: {}\n【请求参数】:{}\n【响应数据】:{}", uriWithAccessToken, dataForLog, result);
return result;
} catch (WxErrorException e) {
WxError error = e.getError();
if (WxConsts.ACCESS_TOKEN_ERROR_CODES.contains(error.getErrorCode())) {
// 强制设置WxMaConfig的access token过期了,这样在下一次请求里就会刷新access token
Lock lock = this.getWxMaConfig().getAccessTokenLock();
lock.lock();
try {
if (StringUtils.equals(this.getWxMaConfig().getAccessToken(), accessToken)) {
this.getWxMaConfig().expireAccessToken();
}
} catch (Exception ex) {
this.getWxMaConfig().expireAccessToken();
} finally {
lock.unlock();
}
if (this.getWxMaConfig().autoRefreshToken() && !doNotAutoRefreshToken) {
log.warn(
"即将重新获取新的access_token,错误代码:{},错误信息:{}", error.getErrorCode(), error.getErrorMsg());
// 下一次不再自动重试
// 当小程序误调用第三方平台专属接口时,第三方无法使用小程序的access token,如果可以继续自动获取token会导致无限循环重试,直到栈溢出
return this.executeInternal(executor, uri, dataForLog, true);
}
}
if (error.getErrorCode() != 0) {
if (error.getErrorCode() == WxMaErrorMsgEnum.CODE_43101.getCode()) {
// 43101 日志太多, 打印为debug, 其他情况打印为warn
log.debug("\n【请求地址】: {}\n【请求参数】:{}\n【错误信息】:{}", uriWithAccessToken, dataForLog, error);
} else {
log.warn("\n【请求地址】: {}\n【请求参数】:{}\n【错误信息】:{}", uriWithAccessToken, dataForLog, error);
}
throw new WxErrorException(error, e);
}
return null;
} catch (IOException e) {
log.warn(
"\n【请求地址】: {}\n【请求参数】:{}\n【异常信息】:{}", uriWithAccessToken, dataForLog, e.getMessage());
throw new WxRuntimeException(e);
}
}
/**
* 设置当前的AccessToken
*
* @param resultContent 响应内容
* @return access token
* @throws WxErrorException 异常
*/
protected String extractAccessToken(String resultContent) throws WxErrorException {
log.debug("access-token response: {}", resultContent);
WxMaConfig config = this.getWxMaConfig();
WxError error = WxError.fromJson(resultContent, WxType.MiniApp);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
}
WxAccessToken accessToken = WxAccessToken.fromJson(resultContent);
config.updateAccessTokenProcessor(accessToken.getAccessToken(), accessToken.getExpiresIn());
return accessToken.getAccessToken();
}
@Override
public WxMaConfig getWxMaConfig() {
if (this.configMap.size() == 1) {
// 只有一个小程序,直接返回其配置即可
return this.configMap.values().iterator().next();
}
return this.configMap.get(WxMaConfigHolder.get());
}
@Override
public void setWxMaConfig(WxMaConfig maConfig) {
final String appid = maConfig.getAppid();
Map<String, WxMaConfig> map = new HashMap<>();
map.put(appid, maConfig);
Map<String, WxMaConfig> configMap = Collections.unmodifiableMap(map);
this.setMultiConfigs(configMap, appid);
}
@Override
public void setMultiConfigs(Map<String, WxMaConfig> configs) {
this.setMultiConfigs(configs, configs.keySet().iterator().next());
}
@Override
@JsonDeserialize
public void setMultiConfigs(Map<String, WxMaConfig> configs, String defaultMiniappId) {
// 防止覆盖配置
if (this.configMap != null) {
this.configMap.putAll(configs);
} else {
this.configMap = Maps.newHashMap(configs);
}
WxMaConfigHolder.set(defaultMiniappId);
this.initHttp();
}
@Override
public void addConfig(String miniappId, WxMaConfig configStorages) {
synchronized (this) {
/*
* 因为commit f74b00cf 默认初始化了configMap,导致使用此方法无法进入if从而触发initHttp(),
* 就会出现HttpClient报NullPointException
*/
if (this.configMap == null || this.configMap.isEmpty()) {
this.setWxMaConfig(configStorages);
} else {
WxMaConfigHolder.set(miniappId);
this.configMap.put(miniappId, configStorages);
}
}
}
@Override
public void removeConfig(String miniappId) {
synchronized (this) {
if (this.configMap.size() == 1) {
this.configMap.remove(miniappId);
log.warn("已删除最后一个小程序配置:{},须立即使用setWxMaConfig或setMultiConfigs添加配置", miniappId);
return;
}
if (WxMaConfigHolder.get().equals(miniappId)) {
this.configMap.remove(miniappId);
final String defaultMpId = this.configMap.keySet().iterator().next();
WxMaConfigHolder.set(defaultMpId);
log.warn("已删除默认小程序配置,小程序【{}】被设为默认配置", defaultMpId);
return;
}
this.configMap.remove(miniappId);
}
}
@Override
public WxMaService switchoverTo(String miniAppId) {
return switchoverTo(miniAppId, null);
}
@Override
public WxMaService switchoverTo(String miniAppId, Function<String, WxMaConfig> func) {
if (this.configMap.containsKey(miniAppId)) {
WxMaConfigHolder.set(miniAppId);
return this;
}
if (func != null) {
WxMaConfig config = func.apply(miniAppId);
if (config != null) {
this.addConfig(miniAppId, config);
return this;
}
}
throw new WxRuntimeException(String.format("无法找到对应【%s】的小程序配置信息,请核实!", miniAppId));
}
@Override
public boolean switchover(String mpId) {
if (this.configMap.containsKey(mpId)) {
WxMaConfigHolder.set(mpId);
return true;
}
log.error("无法找到对应【{}】的小程序配置信息,请核实!", mpId);
return false;
}
@Override
public void setRetrySleepMillis(int retrySleepMillis) {
this.retrySleepMillis = retrySleepMillis;
}
@Override
public void setMaxRetryTimes(int maxRetryTimes) {
this.maxRetryTimes = maxRetryTimes;
}
@Override
public WxMaMsgService getMsgService() {
return this.kefuService;
}
@Override
public WxMaMediaService getMediaService() {
return this.materialService;
}
@Override
public WxMaUserService getUserService() {
return this.userService;
}
@Override
public WxMaQrcodeService getQrcodeService() {
return this.qrCodeService;
}
@Override
public WxMaSchemeService getWxMaSchemeService() {
return schemeService;
}
@Override
public WxMaSubscribeService getSubscribeService() {
return this.subscribeService;
}
@Override
public WxMaAnalysisService getAnalysisService() {
return this.analysisService;
}
@Override
public WxMaCodeService getCodeService() {
return this.codeService;
}
@Override
public WxMaCustomserviceWorkService getCustomserviceWorkService() {
return this.customserviceWorkService;
}
@Override
public WxMaKefuService getKefuService() {
return this.maKefuService;
}
@Override
public WxMaJsapiService getJsapiService() {
return this.jsapiService;
}
@Override
public WxMaSettingService getSettingService() {
return this.settingService;
}
@Override
public WxMaShareService getShareService() {
return this.shareService;
}
@Override
public WxMaRunService getRunService() {
return this.runService;
}
@Override
public WxMaSecurityService getSecurityService() {
return this.securityService;
}
@Override
public WxMaPluginService getPluginService() {
return this.pluginService;
}
@Override
public WxMaExpressService getExpressService() {
return this.expressService;
}
@Override
public WxMaCloudService getCloudService() {
return this.cloudService;
}
@Override
public WxMaInternetService getInternetService() {
return this.internetService;
}
@Override
public WxMaLiveService getLiveService() {
return this.liveService;
}
@Override
public WxMaLiveGoodsService getLiveGoodsService() {
return this.liveGoodsService;
}
@Override
public WxMaLiveMemberService getLiveMemberService() {
return this.liveMemberService;
}
@Override
public WxOcrService getOcrService() {
return this.ocrService;
}
@Override
public WxImgProcService getImgProcService() {
return this.imgProcService;
}
@Override
public WxMaShopSpuService getShopSpuService() {
return this.shopSpuService;
}
@Override
public WxMaShopOrderService getShopOrderService() {
return this.shopOrderService;
}
@Override
public WxMaShopRegisterService getShopRegisterService() {
return this.shopRegisterService;
}
@Override
public WxMaShopAccountService getShopAccountService() {
return this.shopAccountService;
}
@Override
public WxMaShopCatService getShopCatService() {
return this.shopCatService;
}
@Override
public WxMaShopImgService getShopImgService() {
return this.shopImgService;
}
@Override
public WxMaShopAuditService getShopAuditService() {
return this.shopAuditService;
}
@Override
public WxMaShopAfterSaleService getShopAfterSaleService() {
return this.shopAfterSaleService;
}
@Override
public WxMaShopDeliveryService getShopDeliveryService() {
return this.shopDeliveryService;
}
@Override
public WxMaLinkService getLinkService() {
return this.linkService;
}
@Override
public WxMaReimburseInvoiceService getReimburseInvoiceService() {
return this.reimburseInvoiceService;
}
@Override
public WxMaDeviceSubscribeService getDeviceSubscribeService() {
return this.deviceSubscribeService;
}
@Override
public WxMaMarketingService getMarketingService() {
return this.marketingService;
}
@Override
public WxMaImmediateDeliveryService getWxMaImmediateDeliveryService() {
return this.immediateDeliveryService;
}
@Override
public WxMaShopSharerService getShopSharerService() {
return this.shopSharerService;
}
@Override
public WxMaProductService getProductService() {
return this.productService;
}
@Override
public WxMaProductOrderService getProductOrderService() {
return this.productOrderService;
}
@Override
public WxMaShopCouponService getWxMaShopCouponService() {
return this.wxMaShopCouponService;
}
@Override
public WxMaShopPayService getWxMaShopPayService() {
return this.wxMaShopPayService;
}
/**
* 小程序发货信息管理服务
*
* @return getWxMaOrderShippingService
*/
@Override
public WxMaOrderShippingService getWxMaOrderShippingService() {
return this.wxMaOrderShippingService;
}
/**
* 小程序订单管理服务
*
* @return WxMaOrderManagementService
*/
@Override
public WxMaOrderManagementService getWxMaOrderManagementService() {
return this.wxMaOrderManagementService;
}
@Override
public WxMaOpenApiService getWxMaOpenApiService() {
return this.wxMaOpenApiService;
}
@Override
public WxMaVodService getWxMaVodService() {
return this.wxMaVodService;
}
@Override
public WxMaXPayService getWxMaXPayService() {
return this.wxMaXPayService;
}
@Override
public WxMaExpressDeliveryReturnService getWxMaExpressDeliveryReturnService() {
return this.wxMaExpressDeliveryReturnService;
}
@Override
public WxMaPromotionService getWxMaPromotionService() {
return this.wxMaPromotionService;
}
@Override
public String postWithSignature(String url, Object obj) throws WxErrorException {
Gson gson =
new GsonBuilder()
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
.create();
JsonObject jsonObject;
if (obj == null) {
jsonObject = gson.fromJson("{}", JsonObject.class);
} else {
jsonObject = gson.toJsonTree(obj).getAsJsonObject();
}
return this.postWithSignature(url, jsonObject);
}
private String generateNonce() {
byte[] nonce = generateRandomBytes(16);
return base64Encode(nonce).replace("=", "");
}
private byte[] generateRandomBytes(int length) {
byte[] bytes = new byte[length];
new SecureRandom().nextBytes(bytes);
return bytes;
}
private String base64Encode(byte[] data) {
return Base64.getEncoder().encodeToString(data);
}
@Override
public String postWithSignature(String url, JsonObject jsonObject) throws WxErrorException {
long timestamp = System.currentTimeMillis() / 1000;
String appId = this.getWxMaConfig().getWechatMpAppid();
String rndStr = UUID.randomUUID().toString().replace("-", "").substring(0, 30);
String aesKey = this.getWxMaConfig().getApiSignatureAesKey();
String aesKeySn = this.getWxMaConfig().getApiSignatureAesKeySn();
String rsaKeySn = this.getWxMaConfig().getApiSignatureRsaPrivateKeySn();
if (rsaKeySn == null || rsaKeySn.isEmpty()) {
throw new SecurityException("ApiSignatureRsaPrivateKeySn不能为空,请检查配置");
}
jsonObject.addProperty("_n", rndStr);
jsonObject.addProperty("_appid", appId);
jsonObject.addProperty("_timestamp", timestamp);
String plainText = jsonObject.toString();
log.debug("URL:{}加密前请求数据:{}", url, plainText);
String urlPath;
if (url.contains("?")) {
urlPath = url.substring(0, url.indexOf("?"));
} else {
urlPath = url;
}
String aad = urlPath + "|" + appId + "|" + timestamp + "|" + aesKeySn;
byte[] realKey;
try {
realKey = Base64.getDecoder().decode(aesKey);
} catch (Exception ex) {
log.error("解析AESKEY失败 {}", aesKey, ex);
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | true |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaSubscribeServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaSubscribeServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.WxMaSubscribeService;
import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.bean.subscribemsg.CategoryData;
import me.chanjar.weixin.common.bean.subscribemsg.PubTemplateKeyword;
import me.chanjar.weixin.common.bean.subscribemsg.TemplateInfo;
import me.chanjar.weixin.common.bean.subscribemsg.PubTemplateTitleListResult;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser;
import org.apache.commons.lang3.StringUtils;
import java.io.Serializable;
import java.util.List;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Subscribe.*;
/**
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* created on 2019-12-15
*/
@RequiredArgsConstructor
public class WxMaSubscribeServiceImpl implements WxMaSubscribeService {
private final WxMaService service;
@Override
public PubTemplateTitleListResult getPubTemplateTitleList(String[] ids, int start, int limit) throws WxErrorException {
ImmutableMap<String, ? extends Serializable> params = ImmutableMap.of("ids", StringUtils.join(ids, ","),
"start", start, "limit", limit);
String responseText = this.service.get(GET_PUB_TEMPLATE_TITLE_LIST_URL,
Joiner.on("&").withKeyValueSeparator("=").join(params));
return PubTemplateTitleListResult.fromJson(responseText);
}
@Override
public List<PubTemplateKeyword> getPubTemplateKeyWordsById(String id) throws WxErrorException {
String responseText = this.service.get(GET_PUB_TEMPLATE_KEY_WORDS_BY_ID_URL,
Joiner.on("&").withKeyValueSeparator("=").join(ImmutableMap.of("tid", id)));
return WxMaGsonBuilder.create().fromJson(GsonParser.parse(responseText)
.getAsJsonArray("data"), new TypeToken<List<PubTemplateKeyword>>() {
}.getType());
}
@Override
public String addTemplate(String id, List<Integer> keywordIdList, String sceneDesc) throws WxErrorException {
String responseText = this.service.post(TEMPLATE_ADD_URL, ImmutableMap.of("tid", id,
"kidList", keywordIdList.toArray(),
"sceneDesc", sceneDesc));
return GsonParser.parse(responseText).get("priTmplId").getAsString();
}
@Override
public List<TemplateInfo> getTemplateList() throws WxErrorException {
String responseText = this.service.get(TEMPLATE_LIST_URL, null);
return WxMaGsonBuilder.create().fromJson(GsonParser.parse(responseText)
.getAsJsonArray("data"), new TypeToken<List<TemplateInfo>>() {
}.getType());
}
@Override
public boolean delTemplate(String templateId) throws WxErrorException {
this.service.post(TEMPLATE_DEL_URL, ImmutableMap.of("priTmplId", templateId));
return true;
}
@Override
public List<CategoryData> getCategory() throws WxErrorException {
String responseText = this.service.get(GET_CATEGORY_URL, null);
return WxMaGsonBuilder.create().fromJson(GsonParser.parse(responseText)
.getAsJsonArray("data"), new TypeToken<List<CategoryData>>() {
}.getType());
}
@Override
public void sendSubscribeMsg(WxMaSubscribeMessage subscribeMessage) throws WxErrorException {
String responseContent = this.service.post(SUBSCRIBE_MSG_SEND_URL, subscribeMessage.toJson());
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaEmployeeRelationServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaEmployeeRelationServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaEmployeeRelationService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.employee.WxMaSendEmployeeMsgRequest;
import cn.binarywang.wx.miniapp.bean.employee.WxMaUnbindEmployeeRequest;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Employee.SEND_EMPLOYEE_MSG_URL;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Employee.UNBIND_EMPLOYEE_URL;
/**
* 小程序用工关系相关操作接口实现
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* created on 2025-12-19
*/
@RequiredArgsConstructor
public class WxMaEmployeeRelationServiceImpl implements WxMaEmployeeRelationService {
private final WxMaService service;
@Override
public void unbindEmployee(WxMaUnbindEmployeeRequest request) throws WxErrorException {
this.service.post(UNBIND_EMPLOYEE_URL, request.toJson());
}
@Override
public void sendEmployeeMsg(WxMaSendEmployeeMsgRequest request) throws WxErrorException {
this.service.post(SEND_EMPLOYEE_MSG_URL, request.toJson());
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaAnalysisServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaAnalysisServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaAnalysisService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.analysis.*;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser;
import org.apache.commons.lang3.time.DateFormatUtils;
import java.lang.reflect.Type;
import java.util.Date;
import java.util.List;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Analysis.*;
/**
* @author <a href="https://github.com/charmingoh">Charming</a>
* @since 2018-04-28
*/
@RequiredArgsConstructor
public class WxMaAnalysisServiceImpl implements WxMaAnalysisService {
private final WxMaService service;
private static String toJson(Date beginDate, Date endDate) {
JsonObject param = new JsonObject();
param.addProperty("begin_date", DateFormatUtils.format(beginDate, "yyyyMMdd"));
param.addProperty("end_date", DateFormatUtils.format(endDate, "yyyyMMdd"));
return param.toString();
}
@Override
public List<WxMaSummaryTrend> getDailySummaryTrend(Date beginDate, Date endDate) throws WxErrorException {
return getAnalysisResultAsList(GET_DAILY_SUMMARY_TREND_URL, beginDate, endDate,
new TypeToken<List<WxMaSummaryTrend>>() {
}.getType());
}
@Override
public List<WxMaVisitTrend> getDailyVisitTrend(Date beginDate, Date endDate) throws WxErrorException {
return getAnalysisResultAsList(GET_DAILY_VISIT_TREND_URL, beginDate, endDate,
new TypeToken<List<WxMaVisitTrend>>() {
}.getType());
}
@Override
public List<WxMaVisitTrend> getWeeklyVisitTrend(Date beginDate, Date endDate) throws WxErrorException {
return getAnalysisResultAsList(GET_WEEKLY_VISIT_TREND_URL, beginDate, endDate,
new TypeToken<List<WxMaVisitTrend>>() {
}.getType());
}
@Override
public List<WxMaVisitTrend> getMonthlyVisitTrend(Date beginDate, Date endDate) throws WxErrorException {
return getAnalysisResultAsList(GET_MONTHLY_VISIT_TREND_URL, beginDate, endDate,
new TypeToken<List<WxMaVisitTrend>>() {
}.getType());
}
@Override
public WxMaVisitDistribution getVisitDistribution(Date beginDate, Date endDate) throws WxErrorException {
String responseContent = this.service.post(GET_VISIT_DISTRIBUTION_URL, toJson(beginDate, endDate));
return WxMaVisitDistribution.fromJson(responseContent);
}
@Override
public WxMaRetainInfo getDailyRetainInfo(Date beginDate, Date endDate) throws WxErrorException {
return getRetainInfo(beginDate, endDate, GET_DAILY_RETAIN_INFO_URL);
}
@Override
public WxMaRetainInfo getWeeklyRetainInfo(Date beginDate, Date endDate) throws WxErrorException {
return getRetainInfo(beginDate, endDate, GET_WEEKLY_RETAIN_INFO_URL);
}
@Override
public WxMaRetainInfo getMonthlyRetainInfo(Date beginDate, Date endDate) throws WxErrorException {
return getRetainInfo(beginDate, endDate, GET_MONTHLY_RETAIN_INFO_URL);
}
@Override
public List<WxMaVisitPage> getVisitPage(Date beginDate, Date endDate) throws WxErrorException {
return getAnalysisResultAsList(GET_VISIT_PAGE_URL, beginDate, endDate,
new TypeToken<List<WxMaVisitPage>>() {
}.getType());
}
@Override
public WxMaUserPortrait getUserPortrait(Date beginDate, Date endDate) throws WxErrorException {
String responseContent = this.service.post(GET_USER_PORTRAIT_URL, toJson(beginDate, endDate));
return WxMaUserPortrait.fromJson(responseContent);
}
private WxMaRetainInfo getRetainInfo(Date beginDate, Date endDate, String url) throws WxErrorException {
String responseContent = this.service.post(url, toJson(beginDate, endDate));
return WxMaRetainInfo.fromJson(responseContent);
}
/**
* 获取数据分析结果并返回 List,returnType 类型
*
* @param url 链接
* @param returnType 返回的类型
* @param <T> 返回的类型
* @return List 类型的数据
*/
private <T> List<T> getAnalysisResultAsList(String url, Date beginDate, Date endDate, Type returnType) throws WxErrorException {
String responseContent = this.service.post(url, toJson(beginDate, endDate));
JsonObject response = GsonParser.parse(responseContent);
boolean hasList = response.has("list");
if (hasList) {
return WxMaGsonBuilder.create().fromJson(response.getAsJsonArray("list"), returnType);
} else {
return null;
}
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopCouponServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopCouponServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.WxMaShopCouponService;
import cn.binarywang.wx.miniapp.bean.shop.WxMaShopCouponInfo;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopBaseResponse;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopCouponListResponse;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopCouponResponse;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopUserCouponListResponse;
import cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Coupon;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonHelper;
import me.chanjar.weixin.common.util.json.GsonParser;
import static me.chanjar.weixin.common.api.WxConsts.ERR_CODE;
/**
* @author leiin
* created on 2022/7/1 2:49 下午
*/
@RequiredArgsConstructor
@Slf4j
public class WxMaShopCouponServiceImpl implements WxMaShopCouponService {
private final WxMaService wxMaService;
@Override
public WxMaShopBaseResponse addCoupon(WxMaShopCouponInfo couponInfo) throws WxErrorException {
JsonObject json = GsonHelper.buildJsonObject("coupon", couponInfo);
String responseContent = this.wxMaService.post(Coupon.ADD_COUPON, json);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopBaseResponse.class);
}
@Override
public WxMaShopCouponResponse getCoupon(String outCouponId) throws WxErrorException {
JsonObject json = GsonHelper.buildJsonObject("out_coupon_id", outCouponId);
String responseContent = this.wxMaService.post(Coupon.GET_COUPON, json);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopCouponResponse.class);
}
@Override
public WxMaShopCouponListResponse getCouponList(Integer pageSize, Integer offset) throws WxErrorException {
JsonObject json = GsonHelper.buildJsonObject("page_size", pageSize, "offset", offset);
String responseContent = this.wxMaService.post(Coupon.GET_COUPON_LIST, json);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopCouponListResponse.class);
}
@Override
public WxMaShopBaseResponse updateCoupon(WxMaShopCouponInfo couponInfo) throws WxErrorException {
JsonObject json = GsonHelper.buildJsonObject("coupon", couponInfo);
String responseContent = this.wxMaService.post(Coupon.UPDATE_COUPON, json);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopBaseResponse.class);
}
@Override
public WxMaShopBaseResponse updateCouponStatus(String outCouponId, Integer status) throws WxErrorException {
JsonObject json = GsonHelper.buildJsonObject("out_coupon_id", outCouponId, "status", status);
String responseContent = this.wxMaService.post(Coupon.UPDATE_COUPON_STATUS, json);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopBaseResponse.class);
}
@Override
public WxMaShopBaseResponse updateCouponStock(String outCouponId, Integer isUsedNum, Integer receiveNum) throws WxErrorException {
JsonObject stockInfo = GsonHelper.buildJsonObject("issued_num", isUsedNum, "receive_num", receiveNum);
JsonObject stock = GsonHelper.buildJsonObject("out_coupon_id", outCouponId, "stock_info", stockInfo);
JsonObject json = GsonHelper.buildJsonObject("coupon_stock", stock);
String responseContent = this.wxMaService.post(Coupon.UPDATE_COUPON_STOCK, json);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopBaseResponse.class);
}
@Override
public WxMaShopBaseResponse addUserCoupon(String openid, String outUserCouponId,
String outCouponId, Integer status, Long recvTime) throws WxErrorException {
JsonObject userCoupon = GsonHelper.buildJsonObject("out_user_coupon_id", outUserCouponId,
"out_coupon_id", outCouponId,
"status", status);
JsonObject json = GsonHelper.buildJsonObject("openid", openid, "user_coupon", userCoupon,
"recv_time", recvTime);
String responseContent = this.wxMaService.post(Coupon.ADD_USER_COUPON, json);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopBaseResponse.class);
}
@Override
public WxMaShopUserCouponListResponse getUserCouponList(Integer pageSize, Integer offset, String openid) throws WxErrorException {
JsonObject json = GsonHelper.buildJsonObject("page_size", pageSize, "offset", offset,
"openid", openid);
String responseContent = this.wxMaService.post(Coupon.GET_USER_COUPON_LIST, json);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopUserCouponListResponse.class);
}
@Override
public WxMaShopBaseResponse updateUserCoupon(String openid, String outUserCouponId,
String outCouponId, Long useTime, Long recvTime) throws WxErrorException {
JsonObject extInfo = GsonHelper.buildJsonObject("use_time", useTime);
JsonObject userCoupon = GsonHelper.buildJsonObject("out_user_coupon_id", outUserCouponId,
"out_coupon_id", outCouponId, "ext_info", extInfo);
JsonObject json = GsonHelper.buildJsonObject("openid", openid, "user_coupon", userCoupon,
"recv_time", recvTime);
String responseContent = this.wxMaService.post(Coupon.UPDATE_USER_COUPON, json);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopBaseResponse.class);
}
@Override
public WxMaShopBaseResponse updateUserCouponStatus(String openid, String outUserCouponId,
String outCouponId, Integer status) throws WxErrorException {
JsonObject json = GsonHelper.buildJsonObject("openid", openid,
"out_user_coupon_id", outUserCouponId,
"out_coupon_id", outCouponId,
"status", status);
String responseContent = this.wxMaService.post(Coupon.UPDATE_USER_COUPON_STATUS, json);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopBaseResponse.class);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaOrderManagementServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaOrderManagementServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaOrderManagementService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.order.WxMaOrderManagementGetOrderDetailPath;
import cn.binarywang.wx.miniapp.bean.order.WxMaOrderManagementResult;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonHelper;
import me.chanjar.weixin.common.util.json.GsonParser;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.OrderManagement.*;
/**
* @author xzh
* @Description
* @createTime 2025/01/16 15:31
*/
@Slf4j
@RequiredArgsConstructor
public class WxMaOrderManagementServiceImpl implements WxMaOrderManagementService {
private final WxMaService wxMaService;
/**
* 查询订单详情路径
* 注意事项
* 如果没有配置过订单详情路径,会返回成功,其中path为''。
*
* @return WxMaOrderManagementGetOrderDetailPath
* @throws WxErrorException e
*/
@Override
public WxMaOrderManagementGetOrderDetailPath getOrderDetailPath() throws WxErrorException {
return request(GET_ORDER_DETAIL_PATH, new Object(), WxMaOrderManagementGetOrderDetailPath.class);
}
/**
* 配置订单详情路径
* 注意事项
* 调用接口前需要先完成订单中心授权协议签署。
* 请确保配置的path可正常跳转到小程序,并且path必须包含字符串“${商品订单号}”。
*
* @param path 订单详情路径
* @return WxMaOrderManagementResult
* @throws WxErrorException e
*/
@Override
public WxMaOrderManagementResult updateOrderDetailPath(String path) throws WxErrorException {
JsonObject jsonObject = GsonHelper.buildJsonObject("path", path);
return request(UPDATE_ORDER_DETAIL_PATH, jsonObject, WxMaOrderManagementResult.class);
}
private <T> T request(String url, Object request, Class<T> resultT) throws WxErrorException {
String responseContent = this.wxMaService.post(url, request);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, resultT);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopSpuServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopSpuServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.WxMaShopSpuService;
import cn.binarywang.wx.miniapp.bean.shop.WxMaShopSpuInfo;
import cn.binarywang.wx.miniapp.bean.shop.WxMaShopSpuWithoutAuditInfo;
import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopSpuPageRequest;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopAddSpuResponse;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopBaseResponse;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopGetSpuListResponse;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopGetSpuResponse;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonHelper;
import me.chanjar.weixin.common.util.json.GsonParser;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Spu.*;
import static me.chanjar.weixin.common.api.WxConsts.ERR_CODE;
/**
* @author boris
*/
@RequiredArgsConstructor
@Slf4j
public class WxMaShopSpuServiceImpl implements WxMaShopSpuService {
private final WxMaService wxMaService;
@Override
public WxMaShopAddSpuResponse addSpu(WxMaShopSpuInfo spuInfo) throws WxErrorException {
String responseContent = this.wxMaService.post(SPU_ADD_URL, spuInfo);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopAddSpuResponse.class);
}
@Override
public WxMaShopBaseResponse deleteSpu(Integer productId, String outProductId)
throws WxErrorException {
String responseContent = this.wxMaService
.post(SPU_DEL_URL, GsonHelper.buildJsonObject("product_id", productId,
"out_product_id", outProductId));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopBaseResponse.class);
}
@Override
public WxMaShopGetSpuResponse getSpu(Integer productId, String outProductId, Integer needEditSpu)
throws WxErrorException {
String responseContent = this.wxMaService
.post(SPU_GET_URL, GsonHelper.buildJsonObject("product_id", productId,
"out_product_id", outProductId, "need_edit_spu", needEditSpu));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopGetSpuResponse.class);
}
@Override
public WxMaShopGetSpuListResponse getSpuList(WxMaShopSpuPageRequest request)
throws WxErrorException {
String responseContent = this.wxMaService.post(SPU_GET_LIST_URL, request);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopGetSpuListResponse.class);
}
@Override
public WxMaShopAddSpuResponse updateSpu(WxMaShopSpuInfo spuInfo) throws WxErrorException {
String responseContent = this.wxMaService.post(SPU_UPDATE_URL, spuInfo);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopAddSpuResponse.class);
}
@Override
public WxMaShopAddSpuResponse updateSpuWithoutAudit(WxMaShopSpuWithoutAuditInfo spuInfo)
throws WxErrorException {
String responseContent = this.wxMaService.post(SPU_UPDATE_WITHOUT_URL, spuInfo);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopAddSpuResponse.class);
}
@Override
public WxMaShopBaseResponse listingSpu(Integer productId, String outProductId)
throws WxErrorException {
String responseContent = this.wxMaService
.post(SPU_LISTING_URL, GsonHelper.buildJsonObject("product_id", productId,
"out_product_id", outProductId));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopBaseResponse.class);
}
@Override
public WxMaShopBaseResponse delistingSpu(Integer productId, String outProductId)
throws WxErrorException {
String responseContent = this.wxMaService
.post(SPU_DELISTING_URL, GsonHelper.buildJsonObject("product_id", productId,
"out_product_id", outProductId));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopBaseResponse.class);
}
@Override
public WxMaShopBaseResponse deleteAudit(Integer productId, String outProductId)
throws WxErrorException {
String responseContent = this.wxMaService
.post(DEL_AUDIT_URL, GsonHelper.buildJsonObject("product_id", productId,
"out_product_id", outProductId));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopBaseResponse.class);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaPromotionServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaPromotionServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaPromotionService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.promoter.request.*;
import cn.binarywang.wx.miniapp.bean.promoter.response.*;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Promotion.*;
import static me.chanjar.weixin.common.api.WxConsts.ERR_CODE;
/**
* @author zhuangzibin
*/
@RequiredArgsConstructor
@Slf4j
public class WxMaPromotionServiceImpl implements WxMaPromotionService {
private final WxMaService wxMaService;
private final static Integer ERR_CODE_OF_EMPTY_LIST = 103006;
@Override
public WxMaPromotionAddRoleResponse addRole(WxMaPromotionAddRoleRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(PROMOTION_ADD_ROLE, request);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaPromotionAddRoleResponse.class);
}
@Override
public WxMaPromotionGetRoleResponse getRole(WxMaPromotionGetRoleRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(PROMOTION_GET_ROLE, request);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaPromotionGetRoleResponse.class);
}
@Override
public WxMaPromotionUpdateRoleResponse updateRole(WxMaPromoterUpdateRoleRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(PROMOTION_UPDATE_ROLE, request);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaPromotionUpdateRoleResponse.class);
}
@Override
public WxMaPromotionAddPromoterResponse addPromoter(WxMaPromotionAddPromoterRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(PROMOTION_ADD_PROMOTER, request);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaPromotionAddPromoterResponse.class);
}
@Override
public WxMaPromotionGetPromoterResponse getPromoter(WxMaPromotionGetPromoterRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(PROMOTION_GET_PROMOTER, request);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0 || jsonObject.get(ERR_CODE).getAsInt() != ERR_CODE_OF_EMPTY_LIST) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaPromotionGetPromoterResponse.class);
}
@Override
public WxMaPromotionUpdatePromoterResponse updatePromoter(WxMaPromotionUpdatePromoterRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(PROMOTION_UPDATE_PROMOTER, request);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaPromotionUpdatePromoterResponse.class);
}
@Override
public WxMaPromotionGetInvitationMaterialResponse getInvitationMaterial(WxMaPromotionGetInvitationMaterialRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(PROMOTION_GET_INVITATION_MATERIAL, request);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaPromotionGetInvitationMaterialResponse.class);
}
@Override
public WxMaPromotionSendMsgResponse sendMsg(WxMaPromotionSendMsgRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(PROMOTION_SEND_MSG, request);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaPromotionSendMsgResponse.class);
}
@Override
public WxMaPromotionSingleSendMsgResponse singleSendMsg(WxMaPromotionSingleSendMsgRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(PROMOTION_SINGLE_SEND_MSG, request);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaPromotionSingleSendMsgResponse.class);
}
@Override
public WxMaPromotionGetMsgResponse getMsg(WxMaPromotionGetMsgRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(PROMOTION_GET_MSG, request);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaPromotionGetMsgResponse.class);
}
@Override
public WxMaPromotionGetMsgClickDataResponse getMsgClickData(WxMaPromotionGetMsgClickDataRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(PROMOTION_GET_MSG_CLICK_DATA, request);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaPromotionGetMsgClickDataResponse.class);
}
@Override
public WxMaPromotionGetShareMaterialResponse getShareMaterial(WxMaPromotionGetShareMaterialRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(PROMOTION_GET_SHARE_MATERIAL, request);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaPromotionGetShareMaterialResponse.class);
}
@Override
public WxMaPromotionGetRelationResponse getRelation(WxMaPromotionGetRelationRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(PROMOTION_GET_RELATION, request);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0 || jsonObject.get(ERR_CODE).getAsInt() != ERR_CODE_OF_EMPTY_LIST) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaPromotionGetRelationResponse.class);
}
@Override
public WxMaPromotionGetOrderResponse getOrder(WxMaPromotionGetOrderRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(PROMOTION_GET_ORDER, request);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0 || jsonObject.get(ERR_CODE).getAsInt() != ERR_CODE_OF_EMPTY_LIST) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaPromotionGetOrderResponse.class);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaJsapiServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaJsapiServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaJsapiService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.bean.WxJsapiSignature;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.RandomUtils;
import me.chanjar.weixin.common.util.crypto.SHA1;
import me.chanjar.weixin.common.util.json.GsonParser;
import java.util.concurrent.locks.Lock;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Jsapi.GET_JSAPI_TICKET_URL;
/**
* <pre>
* Created by BinaryWang on 2018/8/5.
* </pre>
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
@RequiredArgsConstructor
public class WxMaJsapiServiceImpl implements WxMaJsapiService {
private final WxMaService service;
@Override
public String getCardApiTicket() throws WxErrorException {
return getCardApiTicket(false);
}
@Override
public String getCardApiTicket(boolean forceRefresh) throws WxErrorException {
if (forceRefresh) {
this.service.getWxMaConfig().expireCardApiTicket();
}
if (this.service.getWxMaConfig().isCardApiTicketExpired()) {
Lock lock = this.service.getWxMaConfig().getCardApiTicketLock();
lock.lock();
try {
if (this.service.getWxMaConfig().isCardApiTicketExpired()) {
String responseContent = this.service.get(GET_JSAPI_TICKET_URL + "?type=wx_card", null);
JsonObject tmpJsonObject = GsonParser.parse(responseContent);
String jsapiTicket = tmpJsonObject.get("ticket").getAsString();
int expiresInSeconds = tmpJsonObject.get("expires_in").getAsInt();
this.service.getWxMaConfig().updateCardApiTicket(jsapiTicket, expiresInSeconds);
}
} finally {
lock.unlock();
}
}
return this.service.getWxMaConfig().getCardApiTicket();
}
@Override
public String getJsapiTicket() throws WxErrorException {
return getJsapiTicket(false);
}
@Override
public String getJsapiTicket(boolean forceRefresh) throws WxErrorException {
Lock lock = this.service.getWxMaConfig().getJsapiTicketLock();
lock.lock();
try {
if (forceRefresh) {
this.service.getWxMaConfig().expireJsapiTicket();
}
if (this.service.getWxMaConfig().isJsapiTicketExpired()) {
String responseContent = this.service.get(GET_JSAPI_TICKET_URL + "?type=jsapi", null);
JsonObject tmpJsonObject = GsonParser.parse(responseContent);
String jsapiTicket = tmpJsonObject.get("ticket").getAsString();
int expiresInSeconds = tmpJsonObject.get("expires_in").getAsInt();
this.service.getWxMaConfig().updateJsapiTicket(jsapiTicket, expiresInSeconds);
}
} finally {
lock.unlock();
}
return this.service.getWxMaConfig().getJsapiTicket();
}
@Override
public WxJsapiSignature createJsapiSignature(String url) throws WxErrorException {
long timestamp = System.currentTimeMillis() / 1000;
String randomStr = RandomUtils.getRandomStr();
String jsapiTicket = getJsapiTicket(false);
String signature = SHA1.genWithAmple("jsapi_ticket=" + jsapiTicket,
"noncestr=" + randomStr, "timestamp=" + timestamp, "url=" + url);
return WxJsapiSignature
.builder()
.appId(this.service.getWxMaConfig().getAppid())
.timestamp(timestamp)
.nonceStr(randomStr)
.url(url)
.signature(signature)
.build();
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopOrderServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopOrderServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.WxMaShopOrderService;
import cn.binarywang.wx.miniapp.bean.shop.WxMaShopOrderInfo;
import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopOrderPayRequest;
import cn.binarywang.wx.miniapp.bean.shop.response.*;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonHelper;
import me.chanjar.weixin.common.util.json.GsonParser;
import org.apache.commons.lang3.time.FastDateFormat;
import java.text.Format;
import java.util.Date;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Order.*;
import static me.chanjar.weixin.common.api.WxConsts.ERR_CODE;
/**
* @author boris
*/
@RequiredArgsConstructor
@Slf4j
public class WxMaShopOrderServiceImpl implements WxMaShopOrderService {
private final Format dateFormat = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss");
private static final String MATCH_KEY = "is_matched";
private final WxMaService wxMaService;
@Override
public Boolean checkScene(Integer scene) throws WxErrorException {
String responseContent = this.wxMaService
.post(ORDER_CHECK_SCENE, GsonHelper.buildJsonObject("scene", scene));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return jsonObject.get(MATCH_KEY).getAsBoolean();
}
@Override
public WxMaShopAddOrderResponse addOrder(WxMaShopOrderInfo orderInfo) throws WxErrorException {
return this.post(ORDER_ADD,orderInfo, WxMaShopAddOrderResponse.class);
}
@Override
public WxMaShopBaseResponse orderPay(WxMaShopOrderPayRequest request) throws WxErrorException {
return this.post(ORDER_PAY,request, WxMaShopBaseResponse.class);
}
@Override
public WxMaShopGetOrderResponse getOrder(Long orderId, String outOrderId, String openid) throws WxErrorException {
return this.post(ORDER_GET, GsonHelper.buildJsonObject("order_id", orderId, "out_order_id", outOrderId,
"openid", openid), WxMaShopGetOrderResponse.class);
}
@Override
public WxMaShopGetOrderListResponse getOrderList(Integer page, Integer pageSize, Boolean desc, Date startCreateTime, Date endCreateTime) throws WxErrorException {
JsonObject object = new JsonObject();
object.addProperty("page", page == null ? 1 : page);
object.addProperty("page_size", pageSize == null ? 10 : pageSize);
object.addProperty("desc", desc ? 1 : 2);
if (startCreateTime != null) {
object.addProperty("start_create_time", this.dateFormat.format(startCreateTime));
}
if (endCreateTime != null) {
object.addProperty("end_create_time", this.dateFormat.format(endCreateTime));
}
return this.post(ORDER_GET_LIST, object, WxMaShopGetOrderListResponse.class);
}
@Override
public WxMaShopGetPaymentParamsResponse getPaymentParams(String orderId, String outOrderId, String openid) throws WxErrorException {
return this.post(ORDER_GET_PAYMENT_PARAMS,
GsonHelper.buildJsonObject("order_id", orderId, "out_order_id", outOrderId,
"openid", openid), WxMaShopGetPaymentParamsResponse.class);
}
private <T> T post(String url, Object params, Class<T> classOfT) throws WxErrorException {
String responseContent = this.wxMaService.post(url, params);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, classOfT);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaServiceOkHttpImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaServiceOkHttpImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaStableAccessTokenRequest;
import cn.binarywang.wx.miniapp.config.WxMaConfig;
import me.chanjar.weixin.common.util.http.HttpClientType;
import me.chanjar.weixin.common.util.http.okhttp.DefaultOkHttpClientBuilder;
import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo;
import okhttp3.*;
import org.apache.commons.lang3.StringUtils;
import java.io.IOException;
import java.util.Objects;
/**
* okhttp实现.
*/
public class WxMaServiceOkHttpImpl extends BaseWxMaServiceImpl<OkHttpClient, OkHttpProxyInfo> {
private OkHttpClient httpClient;
private OkHttpProxyInfo httpProxy;
@Override
public void initHttp() {
WxMaConfig wxMpConfigStorage = this.getWxMaConfig();
//设置代理
if (wxMpConfigStorage.getHttpProxyHost() != null && wxMpConfigStorage.getHttpProxyPort() > 0) {
httpProxy = OkHttpProxyInfo.httpProxy(wxMpConfigStorage.getHttpProxyHost(),
wxMpConfigStorage.getHttpProxyPort(),
wxMpConfigStorage.getHttpProxyUsername(),
wxMpConfigStorage.getHttpProxyPassword());
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
clientBuilder.proxy(getRequestHttpProxy().getProxy());
//设置授权
clientBuilder.proxyAuthenticator(new Authenticator() {
@Override
public Request authenticate(Route route, Response response) throws IOException {
String credential = Credentials.basic(httpProxy.getProxyUsername(), httpProxy.getProxyPassword());
return response.request().newBuilder()
.header("Proxy-Authorization", credential)
.build();
}
});
httpClient = clientBuilder.build();
} else {
httpClient = DefaultOkHttpClientBuilder.get().build();
}
}
@Override
public OkHttpClient getRequestHttpClient() {
return httpClient;
}
@Override
public OkHttpProxyInfo getRequestHttpProxy() {
return httpProxy;
}
@Override
public HttpClientType getRequestType() {
return HttpClientType.OK_HTTP;
}
@Override
protected String doGetAccessTokenRequest() throws IOException {
String url = StringUtils.isNotEmpty(this.getWxMaConfig().getAccessTokenUrl()) ?
this.getWxMaConfig().getAccessTokenUrl() :
WxMaService.GET_ACCESS_TOKEN_URL.replace(
WxMaConfig.DEFAULT_API_HOST_URL, this.getWxMaConfig().getEffectiveApiHostUrl());
url = String.format(url, this.getWxMaConfig().getAppid(), this.getWxMaConfig().getSecret());
Request request = new Request.Builder().url(url).get().build();
try (Response response = getRequestHttpClient().newCall(request).execute()) {
return Objects.requireNonNull(response.body()).string();
}
}
@Override
protected String doGetStableAccessTokenRequest(boolean forceRefresh) throws IOException {
String url = StringUtils.isNotEmpty(this.getWxMaConfig().getAccessTokenUrl()) ?
this.getWxMaConfig().getAccessTokenUrl() :
GET_STABLE_ACCESS_TOKEN.replace(
WxMaConfig.DEFAULT_API_HOST_URL, this.getWxMaConfig().getEffectiveApiHostUrl());
WxMaStableAccessTokenRequest wxMaAccessTokenRequest = new WxMaStableAccessTokenRequest();
wxMaAccessTokenRequest.setAppid(this.getWxMaConfig().getAppid());
wxMaAccessTokenRequest.setSecret(this.getWxMaConfig().getSecret());
wxMaAccessTokenRequest.setGrantType("client_credential");
wxMaAccessTokenRequest.setForceRefresh(forceRefresh);
RequestBody body = RequestBody.Companion.create(wxMaAccessTokenRequest.toJson(), MediaType.parse("application/json; charset=utf-8"));
Request request = new Request.Builder().url(url).post(body).build();
try (Response response = getRequestHttpClient().newCall(request).execute()) {
return Objects.requireNonNull(response.body()).string();
}
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaInternetServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaInternetServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaInternetService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.internet.WxMaInternetResponse;
import cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
/**
* 服务端网络相关接口
*
* @author <a href="https://github.com/chutian0124">chutian0124</a>
* created on 2021-09-06
*/
@RequiredArgsConstructor
public class WxMaInternetServiceImpl implements WxMaInternetService {
private final WxMaService wxMaService;
private String sha256(String data, String sessionKey) throws Exception {
Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
SecretKeySpec secret_key = new SecretKeySpec(sessionKey.getBytes(StandardCharsets.UTF_8), "HmacSHA256");
sha256_HMAC.init(secret_key);
byte[] array = sha256_HMAC.doFinal(data.getBytes(StandardCharsets.UTF_8));
StringBuilder sb = new StringBuilder();
for (byte item : array) {
sb.append(Integer.toHexString((item & 0xFF) | 0x100).substring(1, 3));
}
return sb.toString().toUpperCase();
}
@Override
public WxMaInternetResponse getUserEncryptKey(String openid, String signature, String sigMethod) throws WxErrorException {
String url = WxMaApiUrlConstants.Internet.GET_USER_ENCRYPT_KEY + "?openid=" + openid + "&signature=" + signature + "&sig_method=" + sigMethod;
return getWxMaInternetResponse(url);
}
@Override
public WxMaInternetResponse getUserEncryptKey(String openid, String sessionKey) throws WxErrorException {
String signature = null;
try {
signature = sha256("", sessionKey);
} catch (Exception e) {
throw new WxErrorException("签名错误");
}
String url = WxMaApiUrlConstants.Internet.GET_USER_ENCRYPT_KEY + "?sig_method=hmac_sha256&openid=" + openid + "&signature=" + signature;
return getWxMaInternetResponse(url);
}
private WxMaInternetResponse getWxMaInternetResponse(String url) throws WxErrorException {
String responseContent = this.wxMaService.post(url, "");
WxMaInternetResponse response = WxMaGsonBuilder.create().fromJson(responseContent, WxMaInternetResponse.class);
if (response.getErrcode() == -1) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return response;
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaVodServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaVodServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.WxMaVodService;
import cn.binarywang.wx.miniapp.bean.WxMaBaseResponse;
import cn.binarywang.wx.miniapp.bean.vod.*;
import cn.binarywang.wx.miniapp.executor.VodSingleUploadRequestExecutor;
import cn.binarywang.wx.miniapp.executor.VodUploadPartRequestExecutor;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser;
import java.io.File;
import java.util.List;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Vod.*;
@RequiredArgsConstructor
@Slf4j
public class WxMaVodServiceImpl implements WxMaVodService {
private final WxMaService service;
@Override
public List<WxMaVodMediaInfo> listMedia(WxMaVodListMediaRequest mediaRequest) throws WxErrorException {
String responseContent = this.service.post(LIST_MEDIA_URL, mediaRequest.toJson());
JsonObject jsonObject = GsonParser.parse(responseContent);
boolean hasMediaInfoList = jsonObject.has("media_info_list");
if (hasMediaInfoList) {
return WxMaGsonBuilder.create().fromJson(jsonObject.getAsJsonArray("media_info_list"),
new TypeToken<List<WxMaVodMediaInfo>>() {
}.getType());
} else {
return null;
}
}
@Override
public List<WxMaVodDramaInfo> listDrama(WxMaVodListDramaRequest mediaRequest) throws WxErrorException {
String responseContent = this.service.post(LIST_DRAMAS_URL, mediaRequest.toJson());
JsonObject jsonObject = GsonParser.parse(responseContent);
boolean hasMediaInfoList = jsonObject.has("drama_info_list");
if (hasMediaInfoList) {
return WxMaGsonBuilder.create().fromJson(jsonObject.getAsJsonArray("drama_info_list"),
new TypeToken<List<WxMaVodDramaInfo>>() {
}.getType());
} else {
return null;
}
}
@Override
public WxMaVodMediaPlaybackInfo getMediaLink(WxMaVodGetMediaLinkRequest request) throws WxErrorException {
String responseContent = this.service.post(GET_MEDIA_LINK_URL, request.toJson());
WxMaVodGetMediaLinkResponse getDetailResponse = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMaVodGetMediaLinkResponse.class);
if (getDetailResponse.getErrcode() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return getDetailResponse.getMediaInfo();
}
@Override
public WxMaVodMediaInfo getMedia(WxMaVodGetMediaRequest request) throws WxErrorException {
String responseContent = this.service.post(GET_MEDIA_URL, request.toJson());
WxMaVodGetMediaResponse getDetailResponse = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMaVodGetMediaResponse.class);
if (getDetailResponse.getErrcode() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return getDetailResponse.getMediaInfo();
}
@Override
public boolean deleteMedia(WxMaVodDeleteMediaRequest request) throws WxErrorException {
String responseContent = this.service.post(DELETE_MEDIA_URL, request.toJson());
WxMaBaseResponse getDetailResponse = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMaBaseResponse.class);
if (getDetailResponse.getErrcode() != 0) {
throw new WxErrorException(
new WxError(getDetailResponse.getErrcode(), getDetailResponse.getErrmsg()));
}
return true;
}
@Override
public WxMaVodDramaInfo getDrama(WxMaVodGetDramaRequest request) throws WxErrorException {
String responseContent = this.service.post(GET_DRAMA_URL, request.toJson());
WxMaVodGetDramaResponse getDetailResponse = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMaVodGetDramaResponse.class);
if (getDetailResponse.getErrcode() != 0) {
throw new WxErrorException(
new WxError(getDetailResponse.getErrcode(), getDetailResponse.getErrmsg()));
}
return getDetailResponse.getDramaInfo();
}
@Override
public Integer auditDrama(WxMaVodAuditDramaRequest request) throws WxErrorException {
String responseContent = this.service.post(AUDIT_DRAMA_URL, request.toJson());
WxMaVodAuditDramaResponse getDetailResponse = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMaVodAuditDramaResponse.class);
if (getDetailResponse.getErrcode() != 0) {
throw new WxErrorException(
new WxError(getDetailResponse.getErrcode(), getDetailResponse.getErrmsg()));
}
return getDetailResponse.getDramaId();
}
@Override
public WxMaVodGetCdnUsageResponse getCdnUsageData(WxMaVodGetCdnUsageRequest request) throws WxErrorException {
String responseContent = this.service.post(GET_CDN_USAGE_DATA_URL, request.toJson());
WxMaVodGetCdnUsageResponse getDetailResponse = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMaVodGetCdnUsageResponse.class);
if (getDetailResponse.getErrcode() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return getDetailResponse;
}
@Override
public WxMaVodGetCdnLogResponse getCdnLogs(WxMaVodGetCdnLogRequest request) throws WxErrorException {
String responseContent = this.service.post(GET_CDN_LOGS_URL, request.toJson());
WxMaVodGetCdnLogResponse getDetailResponse = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMaVodGetCdnLogResponse.class);
if (getDetailResponse.getErrcode() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return getDetailResponse;
}
@Override
public WxMaVodGetTaskResponse getTask(WxMaVodGetTaskRequest request) throws WxErrorException {
String responseContent = this.service.post(GET_TASK_URL, request.toJson());
WxMaVodGetTaskResponse getDetailResponse = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMaVodGetTaskResponse.class);
if (getDetailResponse.getErrcode() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return getDetailResponse;
}
@Override
public WxMaVodPullUploadResponse pullUpload(WxMaVodPullUploadRequest request) throws WxErrorException {
String responseContent = this.service.post(PULL_UPLOAD_URL, request.toJson());
WxMaVodPullUploadResponse getDetailResponse = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMaVodPullUploadResponse.class);
if (getDetailResponse.getErrcode() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return getDetailResponse;
}
@Override
public WxMaVodSingleFileUploadResult uploadSingleFile(File file, String mediaName, String mediaType) throws WxErrorException {
WxMaVodSingleFileUploadResult result = this.service.execute(
VodSingleUploadRequestExecutor.create(this.service.getRequestHttp(), mediaName, mediaType, null, null, null), SINGLE_FILE_UPLOAD_URL, file);
return result;
}
@Override
public WxMaVodSingleFileUploadResult uploadSingleFile(File file, String mediaName, String mediaType, String coverType, File coverData, String sourceContext) throws WxErrorException {
WxMaVodSingleFileUploadResult result = this.service.execute(
VodSingleUploadRequestExecutor.create(this.service.getRequestHttp(), mediaName, mediaType, coverType, coverData, sourceContext), SINGLE_FILE_UPLOAD_URL, file);
return result;
}
@Override
public WxMaVodApplyUploadResponse applyUpload(WxMaVodApplyUploadRequest request) throws WxErrorException {
String responseContent = this.service.post(APPLY_UPLOAD_URL, request.toJson());
WxMaVodApplyUploadResponse getDetailResponse = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMaVodApplyUploadResponse.class);
if (getDetailResponse.getErrcode() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return getDetailResponse;
}
@Override
public WxMaVodCommitUploadResponse commitUpload(WxMaVodCommitUploadRequest request) throws WxErrorException {
String responseContent = this.service.post(COMMIT_UPLOAD_URL, request.toJson());
WxMaVodCommitUploadResponse getDetailResponse = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMaVodCommitUploadResponse.class);
if (getDetailResponse.getErrcode() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return getDetailResponse;
}
@Override
public WxMaVodUploadPartResult uploadPart(File file, String uploadId, Integer partNumber, Integer resourceType) throws WxErrorException {
WxMaVodUploadPartResult result = this.service.execute(
VodUploadPartRequestExecutor.create(this.service.getRequestHttp(), uploadId, partNumber, resourceType), UPLOAD_PART_URL, file);
return result;
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopImgServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopImgServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.WxMaShopImgService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.bean.result.WxMinishopImageUploadCustomizeResult;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.MinishopUploadRequestCustomizeExecutor;
import java.io.File;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Img.IMG_UPLOAD;
/**
* @author liming1019
*/
@RequiredArgsConstructor
@Slf4j
public class WxMaShopImgServiceImpl implements WxMaShopImgService {
private final WxMaService service;
@Override
public WxMinishopImageUploadCustomizeResult uploadImg(File file) throws WxErrorException {
WxMinishopImageUploadCustomizeResult result = this.service.execute(
MinishopUploadRequestCustomizeExecutor.create(this.service.getRequestHttp(), "0", null), IMG_UPLOAD, file);
return result;
}
@Override
public WxMinishopImageUploadCustomizeResult uploadImg(File file, String respType) throws WxErrorException {
WxMinishopImageUploadCustomizeResult result = this.service.execute(
MinishopUploadRequestCustomizeExecutor.create(this.service.getRequestHttp(), respType, null), IMG_UPLOAD, file);
return result;
}
@Override
public WxMinishopImageUploadCustomizeResult uploadImg(String imgUrl, String respType) throws WxErrorException {
WxMinishopImageUploadCustomizeResult result = this.service.execute(
MinishopUploadRequestCustomizeExecutor.create(this.service.getRequestHttp(), respType, imgUrl), IMG_UPLOAD, null);
return result;
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaOcrServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaOcrServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaService;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.bean.ocr.*;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.requestexecuter.ocr.OcrDiscernRequestExecutor;
import me.chanjar.weixin.common.service.WxOcrService;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Ocr.*;
/**
* ocr 接口实现.
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* created on 2019-06-22
*/
@RequiredArgsConstructor
public class WxMaOcrServiceImpl implements WxOcrService {
private final WxMaService service;
@Override
public WxOcrIdCardResult idCard(String imgUrl) throws WxErrorException {
try {
imgUrl = URLEncoder.encode(imgUrl, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
// ignore cannot happen
}
final String result = this.service.post(String.format(IDCARD, imgUrl), (String) null);
return WxOcrIdCardResult.fromJson(result);
}
@Override
public WxOcrIdCardResult idCard(File imgFile) throws WxErrorException {
String result = this.service.execute(OcrDiscernRequestExecutor.create(this.service.getRequestHttp()),
FILEIDCARD, imgFile);
return WxOcrIdCardResult.fromJson(result);
}
@Override
public WxOcrBankCardResult bankCard(String imgUrl) throws WxErrorException {
try {
imgUrl = URLEncoder.encode(imgUrl, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
// ignore cannot happen
}
final String result = this.service.post(String.format(BANK_CARD, imgUrl), (String) null);
return WxOcrBankCardResult.fromJson(result);
}
@Override
public WxOcrBankCardResult bankCard(File imgFile) throws WxErrorException {
String result = this.service.execute(OcrDiscernRequestExecutor.create(this.service.getRequestHttp()),
FILE_BANK_CARD, imgFile);
return WxOcrBankCardResult.fromJson(result);
}
@Override
public WxOcrDrivingResult driving(String imgUrl) throws WxErrorException {
try {
imgUrl = URLEncoder.encode(imgUrl, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
// ignore cannot happen
}
final String result = this.service.post(String.format(DRIVING, imgUrl), (String) null);
return WxOcrDrivingResult.fromJson(result);
}
@Override
public WxOcrDrivingResult driving(File imgFile) throws WxErrorException {
String result = this.service.execute(OcrDiscernRequestExecutor.create(this.service.getRequestHttp()),
FILE_DRIVING, imgFile);
return WxOcrDrivingResult.fromJson(result);
}
@Override
public WxOcrDrivingLicenseResult drivingLicense(String imgUrl) throws WxErrorException {
try {
imgUrl = URLEncoder.encode(imgUrl, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
// ignore cannot happen
}
final String result = this.service.post(String.format(DRIVING_LICENSE, imgUrl), (String) null);
return WxOcrDrivingLicenseResult.fromJson(result);
}
@Override
public WxOcrDrivingLicenseResult drivingLicense(File imgFile) throws WxErrorException {
String result = this.service.execute(OcrDiscernRequestExecutor.create(this.service.getRequestHttp()),
FILE_DRIVING_LICENSE, imgFile);
return WxOcrDrivingLicenseResult.fromJson(result);
}
@Override
public WxOcrBizLicenseResult bizLicense(String imgUrl) throws WxErrorException {
try {
imgUrl = URLEncoder.encode(imgUrl, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
// ignore cannot happen
}
final String result = this.service.post(String.format(BIZ_LICENSE, imgUrl), (String) null);
return WxOcrBizLicenseResult.fromJson(result);
}
@Override
public WxOcrBizLicenseResult bizLicense(File imgFile) throws WxErrorException {
String result = this.service.execute(OcrDiscernRequestExecutor.create(this.service.getRequestHttp()),
FILE_BIZ_LICENSE, imgFile);
return WxOcrBizLicenseResult.fromJson(result);
}
@Override
public WxOcrCommResult comm(String imgUrl) throws WxErrorException {
try {
imgUrl = URLEncoder.encode(imgUrl, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
// ignore cannot happen
}
final String result = this.service.post(String.format(COMM, imgUrl), (String) null);
return WxOcrCommResult.fromJson(result);
}
@Override
public WxOcrCommResult comm(File imgFile) throws WxErrorException {
String result = this.service.execute(OcrDiscernRequestExecutor.create(this.service.getRequestHttp()),
FILE_COMM, imgFile);
return WxOcrCommResult.fromJson(result);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopDeliveryServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopDeliveryServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.WxMaShopDeliveryService;
import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopDeliveryRecieveRequest;
import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopDeliverySendRequest;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopBaseResponse;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopDeliveryGetCompanyListResponse;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Delivery.*;
import static me.chanjar.weixin.common.api.WxConsts.ERR_CODE;
/**
* @author boris
* @author liming1019
*/
@RequiredArgsConstructor
@Slf4j
public class WxMaShopDeliveryServiceImpl implements WxMaShopDeliveryService {
private final WxMaService wxMaService;
/**
* 获取快递公司列表
*
* @return WxMaShopDeliveryGetCompanyListResponse
* @throws WxErrorException
*/
@Override
public WxMaShopDeliveryGetCompanyListResponse getCompanyList() throws WxErrorException {
String responseContent = this.wxMaService.post(GET_COMPANY_LIST, new JsonObject());
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopDeliveryGetCompanyListResponse.class);
}
/**
* 订单发货
*
* @param request
* @return WxMaShopBaseResponse
* @throws WxErrorException
*/
@Override
public WxMaShopBaseResponse send(WxMaShopDeliverySendRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(DELIVERY_SEND, request);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopBaseResponse.class);
}
/**
* 订单确认收货
*
* @param request
* @return WxMaShopBaseResponse
* @throws WxErrorException
*/
@Override
public WxMaShopBaseResponse receive(WxMaShopDeliveryRecieveRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(DELIVERY_RECEIVE, request);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopBaseResponse.class);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaXPayServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaXPayServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.WxMaXPayService;
import cn.binarywang.wx.miniapp.bean.WxMaBaseResponse;
import cn.binarywang.wx.miniapp.bean.xpay.*;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.XPay.*;
@RequiredArgsConstructor
@Slf4j
public class WxMaXPayServiceImpl implements WxMaXPayService {
private final WxMaService service;
@Override
public WxMaXPayQueryUserBalanceResponse queryUserBalance(WxMaXPayQueryUserBalanceRequest request, WxMaXPaySigParams sigParams) throws WxErrorException {
final String postBody = request.toJson();
final String uri = sigParams.signUriWithBoth(QUERY_USER_BALANCE_URL, postBody);
String responseContent = this.service.post(uri, postBody);
WxMaXPayQueryUserBalanceResponse getDetailResponse = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMaXPayQueryUserBalanceResponse.class);
if (getDetailResponse.getErrcode() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return getDetailResponse;
}
@Override
public WxMaXPayCurrencyPayResponse currencyPay(WxMaXPayCurrencyPayRequest request, WxMaXPaySigParams sigParams) throws WxErrorException {
final String postBody = request.toJson();
final String uri = sigParams.signUriWithBoth(CURRENCY_PAY_URL, postBody);
String responseContent = this.service.post(uri, postBody);
WxMaXPayCurrencyPayResponse getDetailResponse = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMaXPayCurrencyPayResponse.class);
if (getDetailResponse.getErrcode() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return getDetailResponse;
}
@Override
public WxMaXPayQueryOrderResponse queryOrder(WxMaXPayQueryOrderRequest request, WxMaXPaySigParams sigParams) throws WxErrorException {
final String postBody = request.toJson();
final String uri = sigParams.signUriWithPay(QUERY_ORDER_URL, postBody);
String responseContent = this.service.post(uri, postBody);
WxMaXPayQueryOrderResponse getDetailResponse = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMaXPayQueryOrderResponse.class);
if (getDetailResponse.getErrcode() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return getDetailResponse;
}
@Override
public WxMaXPayCancelCurrencyPayResponse cancelCurrencyPay(WxMaXPayCancelCurrencyPayRequest request, WxMaXPaySigParams sigParams) throws WxErrorException {
final String postBody = request.toJson();
final String uri = sigParams.signUriWithBoth(CANCEL_CURRENCY_PAY_URL, postBody);
String responseContent = this.service.post(uri, postBody);
WxMaXPayCancelCurrencyPayResponse getDetailResponse = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMaXPayCancelCurrencyPayResponse.class);
if (getDetailResponse.getErrcode() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return getDetailResponse;
}
@Override
public boolean notifyProvideGoods(WxMaXPayNotifyProvideGoodsRequest request, WxMaXPaySigParams sigParams) throws WxErrorException {
final String postBody = request.toJson();
final String uri = sigParams.signUriWithPay(NOTIFY_PROVIDE_GOODS_URL, postBody);
String responseContent = this.service.post(uri, postBody);
WxMaBaseResponse getDetailResponse = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMaBaseResponse.class);
if (getDetailResponse.getErrcode() != 0) {
throw new WxErrorException(
new WxError(getDetailResponse.getErrcode(), getDetailResponse.getErrmsg()));
}
return true;
}
@Override
public WxMaXPayPresentCurrencyResponse presentCurrency(WxMaXPayPresentCurrencyRequest request, WxMaXPaySigParams sigParams) throws WxErrorException {
final String postBody = request.toJson();
final String uri = sigParams.signUriWithPay(PRESENT_CURRENCY_URL, postBody);
String responseContent = this.service.post(uri, postBody);
WxMaXPayPresentCurrencyResponse getDetailResponse = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMaXPayPresentCurrencyResponse.class);
if (getDetailResponse.getErrcode() != 0) {
throw new WxErrorException(
new WxError(getDetailResponse.getErrcode(), getDetailResponse.getErrmsg()));
}
return getDetailResponse;
}
@Override
public WxMaXPayPresentGoodsResponse presentGoods(WxMaXPayPresentGoodsRequest request, WxMaXPaySigParams sigParams) throws WxErrorException {
final String postBody = request.toJson();
final String uri = sigParams.signUriWithPay(PRESENT_GOODS_URL, postBody);
String responseContent = this.service.post(uri, postBody);
WxMaXPayPresentGoodsResponse getDetailResponse = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMaXPayPresentGoodsResponse.class);
if (getDetailResponse.getErrcode() != 0) {
throw new WxErrorException(
new WxError(getDetailResponse.getErrcode(), getDetailResponse.getErrmsg()));
}
return getDetailResponse;
}
@Override
public WxMaXPayDownloadBillResponse downloadBill(WxMaXPayDownloadBillRequest request, WxMaXPaySigParams sigParams) throws WxErrorException {
final String postBody = request.toJson();
final String uri = sigParams.signUriWithPay(DOWNLOAD_BILL_URL, postBody);
String responseContent = this.service.post(uri, postBody);
WxMaXPayDownloadBillResponse getDetailResponse = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMaXPayDownloadBillResponse.class);
if (getDetailResponse.getErrcode() != 0) {
throw new WxErrorException(
new WxError(getDetailResponse.getErrcode(), getDetailResponse.getErrmsg()));
}
return getDetailResponse;
}
@Override
public WxMaXPayRefundOrderResponse refundOrder(WxMaXPayRefundOrderRequest request, WxMaXPaySigParams sigParams) throws WxErrorException {
final String postBody = request.toJson();
final String uri = sigParams.signUriWithPay(REFUND_ORDER_URL, postBody);
String responseContent = this.service.post(uri, postBody);
WxMaXPayRefundOrderResponse getDetailResponse = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMaXPayRefundOrderResponse.class);
if (getDetailResponse.getErrcode() != 0) {
throw new WxErrorException(
new WxError(getDetailResponse.getErrcode(), getDetailResponse.getErrmsg()));
}
return getDetailResponse;
}
@Override
public WxMaXPayCreateWithdrawOrderResponse createWithdrawOrder(WxMaXPayCreateWithdrawOrderRequest request, WxMaXPaySigParams sigParams) throws WxErrorException {
final String postBody = request.toJson();
final String uri = sigParams.signUriWithPay(CREATE_WITHDRAW_ORDER_URL, postBody);
String responseContent = this.service.post(uri, postBody);
WxMaXPayCreateWithdrawOrderResponse getDetailResponse = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMaXPayCreateWithdrawOrderResponse.class);
if (getDetailResponse.getErrcode() != 0) {
throw new WxErrorException(
new WxError(getDetailResponse.getErrcode(), getDetailResponse.getErrmsg()));
}
return getDetailResponse;
}
@Override
public WxMaXPayQueryWithdrawOrderResponse queryWithdrawOrder(WxMaXPayQueryWithdrawOrderRequest request, WxMaXPaySigParams sigParams) throws WxErrorException {
final String postBody = request.toJson();
final String uri = sigParams.signUriWithPay(QUERY_WITHDRAW_ORDER_URL, postBody);
String responseContent = this.service.post(uri, postBody);
WxMaXPayQueryWithdrawOrderResponse getDetailResponse = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMaXPayQueryWithdrawOrderResponse.class);
if (getDetailResponse.getErrcode() != 0) {
throw new WxErrorException(
new WxError(getDetailResponse.getErrcode(), getDetailResponse.getErrmsg()));
}
return getDetailResponse;
}
@Override
public boolean startUploadGoods(WxMaXPayStartUploadGoodsRequest request, WxMaXPaySigParams sigParams) throws WxErrorException {
final String postBody = request.toJson();
final String uri = sigParams.signUriWithPay(START_UPLOAD_GOODS_URL, postBody);
String responseContent = this.service.post(uri, postBody);
WxMaBaseResponse getDetailResponse = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMaBaseResponse.class);
if (getDetailResponse.getErrcode() != 0) {
throw new WxErrorException(
new WxError(getDetailResponse.getErrcode(), getDetailResponse.getErrmsg()));
}
return true;
}
@Override
public WxMaXPayQueryUploadGoodsResponse queryUploadGoods(WxMaXPayQueryUploadGoodsRequest request, WxMaXPaySigParams sigParams) throws WxErrorException {
final String postBody = request.toJson();
final String uri = sigParams.signUriWithPay(QUERY_UPLOAD_GOODS_URL, postBody);
String responseContent = this.service.post(uri, postBody);
WxMaXPayQueryUploadGoodsResponse getDetailResponse = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMaXPayQueryUploadGoodsResponse.class);
if (getDetailResponse.getErrcode() != 0) {
throw new WxErrorException(
new WxError(getDetailResponse.getErrcode(), getDetailResponse.getErrmsg()));
}
return getDetailResponse;
}
@Override
public boolean startPublishGoods(WxMaXPayStartPublishGoodsRequest request, WxMaXPaySigParams sigParams) throws WxErrorException {
final String postBody = request.toJson();
final String uri = sigParams.signUriWithPay(START_PUBLISH_GOODS_URL, postBody);
String responseContent = this.service.post(uri, postBody);
WxMaBaseResponse getDetailResponse = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMaBaseResponse.class);
if (getDetailResponse.getErrcode() != 0) {
throw new WxErrorException(
new WxError(getDetailResponse.getErrcode(), getDetailResponse.getErrmsg()));
}
return true;
}
@Override
public WxMaXPayQueryPublishGoodsResponse queryPublishGoods(WxMaXPayQueryPublishGoodsRequest request, WxMaXPaySigParams sigParams) throws WxErrorException {
final String postBody = request.toJson();
final String uri = sigParams.signUriWithPay(QUERY_PUBLISH_GOODS_URL, postBody);
String responseContent = this.service.post(uri, postBody);
WxMaXPayQueryPublishGoodsResponse getDetailResponse = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMaXPayQueryPublishGoodsResponse.class);
if (getDetailResponse.getErrcode() != 0) {
throw new WxErrorException(
new WxError(getDetailResponse.getErrcode(), getDetailResponse.getErrmsg()));
}
return getDetailResponse;
}
@Override
public WxMaXPayQueryBizBalanceResponse queryBizBalance(WxMaXPayQueryBizBalanceRequest request, WxMaXPaySigParams sigParams) throws WxErrorException {
final String postBody = request.toJson();
final String uri = sigParams.signUriWithPay(QUERY_BIZ_BALANCE_URL, postBody);
String responseContent = this.service.post(uri, postBody);
WxMaXPayQueryBizBalanceResponse getDetailResponse = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMaXPayQueryBizBalanceResponse.class);
if (getDetailResponse.getErrcode() != 0) {
throw new WxErrorException(
new WxError(getDetailResponse.getErrcode(), getDetailResponse.getErrmsg()));
}
return getDetailResponse;
}
@Override
public WxMaXPayQueryTransferAccountResponse queryTransferAccount(WxMaXPayQueryTransferAccountRequest request, WxMaXPaySigParams sigParams) throws WxErrorException {
final String postBody = request.toJson();
final String uri = sigParams.signUriWithPay(QUERY_TRANSFER_ACCOUNT_URL, postBody);
String responseContent = this.service.post(uri, postBody);
WxMaXPayQueryTransferAccountResponse getDetailResponse = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMaXPayQueryTransferAccountResponse.class);
if (getDetailResponse.getErrcode() != 0) {
throw new WxErrorException(
new WxError(getDetailResponse.getErrcode(), getDetailResponse.getErrmsg()));
}
return getDetailResponse;
}
@Override
public WxMaXPayQueryAdverFundsResponse queryAdverFunds(WxMaXPayQueryAdverFundsRequest request, WxMaXPaySigParams sigParams) throws WxErrorException {
final String postBody = request.toJson();
final String uri = sigParams.signUriWithPay(QUERY_ADVER_FUNDS_URL, postBody);
String responseContent = this.service.post(uri, postBody);
WxMaXPayQueryAdverFundsResponse getDetailResponse = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMaXPayQueryAdverFundsResponse.class);
if (getDetailResponse.getErrcode() != 0) {
throw new WxErrorException(
new WxError(getDetailResponse.getErrcode(), getDetailResponse.getErrmsg()));
}
return getDetailResponse;
}
@Override
public WxMaXPayCreateFundsBillResponse createFundsBill(WxMaXPayCreateFundsBillRequest request, WxMaXPaySigParams sigParams) throws WxErrorException {
final String postBody = request.toJson();
final String uri = sigParams.signUriWithPay(CREATE_FUNDS_BILL_URL, postBody);
String responseContent = this.service.post(uri, postBody);
WxMaXPayCreateFundsBillResponse getDetailResponse = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMaXPayCreateFundsBillResponse.class);
if (getDetailResponse.getErrcode() != 0) {
throw new WxErrorException(
new WxError(getDetailResponse.getErrcode(), getDetailResponse.getErrmsg()));
}
return getDetailResponse;
}
@Override
public WxMaBaseResponse bindTransferAccount(WxMaXPayBindTransferAccountRequest request, WxMaXPaySigParams sigParams) throws WxErrorException {
final String postBody = request.toJson();
final String uri = sigParams.signUriWithPay(BIND_TRANSFER_ACCOUNT_URL, postBody);
String responseContent = this.service.post(uri, postBody);
WxMaBaseResponse getDetailResponse = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMaBaseResponse.class);
if (getDetailResponse.getErrcode() != 0) {
throw new WxErrorException(
new WxError(getDetailResponse.getErrcode(), getDetailResponse.getErrmsg()));
}
return getDetailResponse;
}
@Override
public WxMaXPayQueryFundsBillResponse queryFundsBill(WxMaXPayQueryFundsBillRequest request, WxMaXPaySigParams sigParams) throws WxErrorException {
final String postBody = request.toJson();
final String uri = sigParams.signUriWithPay(QUERY_FUNDS_BILL_URL, postBody);
String responseContent = this.service.post(uri, postBody);
WxMaXPayQueryFundsBillResponse getDetailResponse = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMaXPayQueryFundsBillResponse.class);
if (getDetailResponse.getErrcode() != 0) {
throw new WxErrorException(
new WxError(getDetailResponse.getErrcode(), getDetailResponse.getErrmsg()));
}
return getDetailResponse;
}
@Override
public WxMaXPayQueryRecoverBillResponse queryRecoverBill(WxMaXPayQueryRecoverBillRequest request, WxMaXPaySigParams sigParams) throws WxErrorException {
final String postBody = request.toJson();
final String uri = sigParams.signUriWithPay(QUERY_RECOVER_BILL_URL, postBody);
String responseContent = this.service.post(uri, postBody);
WxMaXPayQueryRecoverBillResponse getDetailResponse = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMaXPayQueryRecoverBillResponse.class);
if (getDetailResponse.getErrcode() != 0) {
throw new WxErrorException(
new WxError(getDetailResponse.getErrcode(), getDetailResponse.getErrmsg()));
}
return getDetailResponse;
}
@Override
public WxMaXPayGetComplaintListResponse getComplaintList(WxMaXPayGetComplaintListRequest request, WxMaXPaySigParams sigParams) throws WxErrorException {
final String postBody = request.toJson();
final String uri = sigParams.signUriWithPay(GET_COMPLAINT_LIST_URL, postBody);
String responseContent = this.service.post(uri, postBody);
WxMaXPayGetComplaintListResponse getDetailResponse = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMaXPayGetComplaintListResponse.class);
if (getDetailResponse.getErrcode() != 0) {
throw new WxErrorException(
new WxError(getDetailResponse.getErrcode(), getDetailResponse.getErrmsg()));
}
return getDetailResponse;
}
@Override
public WxMaXPayGetComplaintDetailResponse getComplaintDetail(WxMaXPayGetComplaintDetailRequest request, WxMaXPaySigParams sigParams) throws WxErrorException {
final String postBody = request.toJson();
final String uri = sigParams.signUriWithPay(GET_COMPLAINT_DETAIL_URL, postBody);
String responseContent = this.service.post(uri, postBody);
WxMaXPayGetComplaintDetailResponse getDetailResponse = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMaXPayGetComplaintDetailResponse.class);
if (getDetailResponse.getErrcode() != 0) {
throw new WxErrorException(
new WxError(getDetailResponse.getErrcode(), getDetailResponse.getErrmsg()));
}
return getDetailResponse;
}
@Override
public WxMaXPayGetNegotiationHistoryResponse getNegotiationHistory(WxMaXPayGetNegotiationHistoryRequest request, WxMaXPaySigParams sigParams) throws WxErrorException {
final String postBody = request.toJson();
final String uri = sigParams.signUriWithPay(GET_NEGOTIATION_HISTORY_URL, postBody);
String responseContent = this.service.post(uri, postBody);
WxMaXPayGetNegotiationHistoryResponse getDetailResponse = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMaXPayGetNegotiationHistoryResponse.class);
if (getDetailResponse.getErrcode() != 0) {
throw new WxErrorException(
new WxError(getDetailResponse.getErrcode(), getDetailResponse.getErrmsg()));
}
return getDetailResponse;
}
@Override
public WxMaBaseResponse responseComplaint(WxMaXPayResponseComplaintRequest request, WxMaXPaySigParams sigParams) throws WxErrorException {
final String postBody = request.toJson();
final String uri = sigParams.signUriWithPay(RESPONSE_COMPLAINT_URL, postBody);
String responseContent = this.service.post(uri, postBody);
WxMaBaseResponse getDetailResponse = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMaBaseResponse.class);
if (getDetailResponse.getErrcode() != 0) {
throw new WxErrorException(
new WxError(getDetailResponse.getErrcode(), getDetailResponse.getErrmsg()));
}
return getDetailResponse;
}
@Override
public WxMaBaseResponse completeComplaint(WxMaXPayCompleteComplaintRequest request, WxMaXPaySigParams sigParams) throws WxErrorException {
final String postBody = request.toJson();
final String uri = sigParams.signUriWithPay(COMPLETE_COMPLAINT_URL, postBody);
String responseContent = this.service.post(uri, postBody);
WxMaBaseResponse getDetailResponse = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMaBaseResponse.class);
if (getDetailResponse.getErrcode() != 0) {
throw new WxErrorException(
new WxError(getDetailResponse.getErrcode(), getDetailResponse.getErrmsg()));
}
return getDetailResponse;
}
@Override
public WxMaXPayUploadVpFileResponse uploadVpFile(WxMaXPayUploadVpFileRequest request, WxMaXPaySigParams sigParams) throws WxErrorException {
final String postBody = request.toJson();
final String uri = sigParams.signUriWithPay(UPLOAD_VP_FILE_URL, postBody);
String responseContent = this.service.post(uri, postBody);
WxMaXPayUploadVpFileResponse getDetailResponse = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMaXPayUploadVpFileResponse.class);
if (getDetailResponse.getErrcode() != 0) {
throw new WxErrorException(
new WxError(getDetailResponse.getErrcode(), getDetailResponse.getErrmsg()));
}
return getDetailResponse;
}
@Override
public WxMaXPayGetUploadFileSignResponse getUploadFileSign(WxMaXPayGetUploadFileSignRequest request, WxMaXPaySigParams sigParams) throws WxErrorException {
final String postBody = request.toJson();
final String uri = sigParams.signUriWithPay(GET_UPLOAD_FILE_SIGN_URL, postBody);
String responseContent = this.service.post(uri, postBody);
WxMaXPayGetUploadFileSignResponse getDetailResponse = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMaXPayGetUploadFileSignResponse.class);
if (getDetailResponse.getErrcode() != 0) {
throw new WxErrorException(
new WxError(getDetailResponse.getErrcode(), getDetailResponse.getErrmsg()));
}
return getDetailResponse;
}
@Override
public WxMaXPayDownloadAdverfundsOrderResponse downloadAdverfundsOrder(WxMaXPayDownloadAdverfundsOrderRequest request, WxMaXPaySigParams sigParams) throws WxErrorException {
final String postBody = request.toJson();
final String uri = sigParams.signUriWithPay(DOWNLOAD_ADVERFUNDS_ORDER_URL, postBody);
String responseContent = this.service.post(uri, postBody);
WxMaXPayDownloadAdverfundsOrderResponse getDetailResponse = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMaXPayDownloadAdverfundsOrderResponse.class);
if (getDetailResponse.getErrcode() != 0) {
throw new WxErrorException(
new WxError(getDetailResponse.getErrcode(), getDetailResponse.getErrmsg()));
}
return getDetailResponse;
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaLiveGoodsServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaLiveGoodsServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaLiveGoodsService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveGoodInfo;
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveResult;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonHelper;
import me.chanjar.weixin.common.util.json.GsonParser;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Broadcast.Goods.*;
/**
* <pre>
* Created by lipengjun on 2020/6/29.
* </pre>
*
* @author <a href="https://github.com/lipengjun92">lipengjun (939961241@qq.com)</a>
*/
@RequiredArgsConstructor
public class WxMaLiveGoodsServiceImpl implements WxMaLiveGoodsService {
private final WxMaService wxMaService;
@Override
public WxMaLiveResult addGoods(WxMaLiveGoodInfo goods) throws WxErrorException {
return WxMaLiveResult.fromJson(this.wxMaService.post(ADD_GOODS,
GsonHelper.buildJsonObject("goodsInfo", goods)));
}
@Override
public boolean resetAudit(Integer auditId, Integer goodsId) throws WxErrorException {
this.wxMaService.post(RESET_AUDIT_GOODS,
GsonHelper.buildJsonObject("auditId", auditId, "goodsId", goodsId));
return true;
}
@Override
public String auditGoods(Integer goodsId) throws WxErrorException {
String responseContent = this.wxMaService.post(AUDIT_GOODS,
GsonHelper.buildJsonObject("goodsId", goodsId));
return GsonParser.parse(responseContent).get("auditId").getAsString();
}
@Override
public boolean deleteGoods(Integer goodsId) throws WxErrorException {
this.wxMaService.post(DELETE_GOODS, GsonHelper.buildJsonObject("goodsId", goodsId));
return true;
}
@Override
public boolean updateGoods(WxMaLiveGoodInfo goods) throws WxErrorException {
Map<String, Object> map = new HashMap<>(2);
map.put("goodsInfo", goods);
this.wxMaService.post(UPDATE_GOODS, WxMaGsonBuilder.create().toJson(map));
return true;
}
@Override
public WxMaLiveResult getGoodsWareHouse(List<Integer> goodsIds) throws WxErrorException {
Map<String, Object> map = new HashMap<>(2);
map.put("goods_ids", goodsIds);
String responseContent = this.wxMaService.post(GET_GOODS_WARE_HOUSE, WxMaGsonBuilder.create().toJson(map));
return WxMaLiveResult.fromJson(responseContent);
}
@Override
public WxMaLiveResult getApprovedGoods(Integer offset, Integer limit, Integer status) throws WxErrorException {
ImmutableMap<String, ? extends Serializable> params = ImmutableMap.of("status", status, "offset", offset, "limit", limit);
String responseContent = wxMaService.get(GET_APPROVED_GOODS, Joiner.on("&").withKeyValueSeparator("=").join(params));
JsonObject jsonObject = GsonParser.parse(responseContent);
JsonArray goodsArr = jsonObject.getAsJsonArray("goods");
if (!goodsArr.isEmpty()) {
for (int i = 0; i < goodsArr.size(); i++) {
// 接口返回key是驼峰
JsonObject goods = (JsonObject) goodsArr.get(i);
goods.addProperty("goods_id", goods.get("goodsId").getAsInt());
goods.addProperty("cover_img_url", goods.get("coverImgUrl").getAsString());
goods.addProperty("price_type", goods.get("priceType").getAsInt());
goods.addProperty("third_party_tag", goods.get("thirdPartyTag").getAsInt());
goods.addProperty("audit_status", status);
}
}
return WxMaLiveResult.fromJson(jsonObject.toString());
}
@Override
public boolean setKey(List<String> goodsKey) throws WxErrorException {
Map<String, Object> map = new HashMap<>(1);
map.put("goodsKey", goodsKey);
this.wxMaService.post(SET_KEY, WxMaGsonBuilder.create().toJson(map));
return true;
}
@Override
public List<String> getKey() throws WxErrorException {
String responseContent = this.wxMaService.get(GET_KEY, null);
JsonObject jsonObject = GsonParser.parse(responseContent);
boolean vendorGoodsKey = jsonObject.has("vendorGoodsKey");
if (vendorGoodsKey) {
return WxMaGsonBuilder.create().fromJson(jsonObject.getAsJsonArray("vendorGoodsKey"),
new TypeToken<List<String>>() {
}.getType());
} else {
return null;
}
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaMediaServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaMediaServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaMediaService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.bean.CommonUploadParam;
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.fs.FileUtils;
import me.chanjar.weixin.common.util.http.BaseMediaDownloadRequestExecutor;
import me.chanjar.weixin.common.util.http.RequestExecutor;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.UUID;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Media.MEDIA_GET_URL;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Media.MEDIA_UPLOAD_URL;
/**
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
@RequiredArgsConstructor
public class WxMaMediaServiceImpl implements WxMaMediaService {
private final WxMaService wxMaService;
@Override
public WxMediaUploadResult uploadMedia(String mediaType, String fileType, InputStream inputStream) throws WxErrorException {
try {
return this.uploadMedia(mediaType, FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), fileType));
} catch (IOException e) {
throw new WxErrorException(WxError.builder().errorMsg(e.getMessage()).build(), e);
}
}
@Override
public WxMediaUploadResult uploadMedia(String mediaType, File file) throws WxErrorException {
// return this.wxMaService.execute(MediaUploadRequestExecutor.create(this.wxMaService.getRequestHttp()), url, file);
String url = String.format(MEDIA_UPLOAD_URL, mediaType);
String result = wxMaService.upload(url, CommonUploadParam.fromFile("media", file));
return WxMediaUploadResult.fromJson(result);
}
@Override
public File getMedia(String mediaId) throws WxErrorException {
try {
RequestExecutor<File, String> executor = BaseMediaDownloadRequestExecutor
.create(this.wxMaService.getRequestHttp(), Files.createTempDirectory("wxma").toFile());
return this.wxMaService.execute(executor, MEDIA_GET_URL, "media_id=" + mediaId);
} catch (IOException e) {
throw new WxErrorException(WxError.builder().errorMsg(e.getMessage()).build(), e);
}
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaCloudServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaCloudServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaCloudService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.cloud.*;
import cn.binarywang.wx.miniapp.bean.cloud.request.WxCloudSendSmsV2Request;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import org.apache.commons.lang3.StringUtils;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Cloud.*;
/**
* 云开发相关接口实现类.
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* created on 2020-01-22
*/
@Slf4j
@RequiredArgsConstructor
public class WxMaCloudServiceImpl implements WxMaCloudService {
private static final Joiner blankJoiner = Joiner.on("").skipNulls();
private final WxMaService wxMaService;
@Override
public String invokeCloudFunction(String name, String body) throws WxErrorException {
String cloudEnv = this.wxMaService.getWxMaConfig().getCloudEnv();
return invokeCloudFunction(cloudEnv, name, body);
}
@Override
public String invokeCloudFunction(String env, String name, String body) throws WxErrorException {
String cloudEnv = this.wxMaService.getWxMaConfig().getCloudEnv();
final String response = this.wxMaService.post(String.format(INVOKE_CLOUD_FUNCTION_URL, cloudEnv, name), body);
return GsonParser.parse(response).get("resp_data").getAsString();
}
@Override
public List<String> add(String collection, List<?> list) throws WxErrorException {
String jsonData = WxMaGsonBuilder.create().toJson(list);
String query = blankJoiner.join(
"db.collection('", collection, "')",
".add({data: ", jsonData, "})");
JsonObject params = new JsonObject();
params.addProperty("env", this.wxMaService.getWxMaConfig().getCloudEnv());
params.addProperty("query", query);
String responseContent = wxMaService.post(DATABASE_ADD_URL, params.toString());
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent));
}
JsonArray idArray = jsonObject.getAsJsonArray("id_list");
List<String> idList = new ArrayList<>();
for (JsonElement id : idArray) {
idList.add(id.getAsString());
}
return idList;
}
@Override
public String add(String collection, Object obj) throws WxErrorException {
String jsonData = WxMaGsonBuilder.create().toJson(obj);
String query = blankJoiner.join(
"db.collection('", collection, "')",
".add({data: ", jsonData, "})");
JsonObject params = new JsonObject();
params.addProperty("env", this.wxMaService.getWxMaConfig().getCloudEnv());
params.addProperty("query", query);
String responseContent = wxMaService.post(DATABASE_ADD_URL, params.toString());
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent));
}
JsonArray idArray = jsonObject.getAsJsonArray("id_list");
return idArray.getAsString();
}
@Override
public JsonArray databaseAdd(String query) throws WxErrorException {
String cloudEnv = this.wxMaService.getWxMaConfig().getCloudEnv();
return databaseAdd(cloudEnv, query);
}
@Override
public JsonArray databaseAdd(String env, String query) throws WxErrorException {
String response = this.wxMaService.post(DATABASE_ADD_URL, ImmutableMap.of("env", env, "query", query));
return GsonParser.parse(response).get("id_list").getAsJsonArray();
}
@Override
public Integer delete(String collection, String whereJson) throws WxErrorException {
String query = blankJoiner.join(
"db.collection('", collection, "')",
".where(", whereJson, ").remove()");
JsonObject params = new JsonObject();
params.addProperty("env", this.wxMaService.getWxMaConfig().getCloudEnv());
params.addProperty("query", query);
String responseContent = wxMaService.post(DATABASE_DELETE_URL, params.toString());
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent));
}
return jsonObject.get("deleted").getAsInt();
}
@Override
public int databaseDelete(String query) throws WxErrorException {
String cloudEnv = this.wxMaService.getWxMaConfig().getCloudEnv();
return databaseDelete(cloudEnv, query);
}
@Override
public int databaseDelete(String env, String query) throws WxErrorException {
String response = this.wxMaService.post(DATABASE_DELETE_URL, ImmutableMap.of("env", env, "query", query));
return GsonParser.parse(response).get("deleted").getAsInt();
}
@Override
public WxCloudDatabaseUpdateResult update(String collection, String whereJson, String updateJson) throws WxErrorException {
String query = blankJoiner.join(
"db.collection('", collection, "')",
".where(", whereJson, ").update({data:", updateJson, " })");
JsonObject params = new JsonObject();
params.addProperty("env", this.wxMaService.getWxMaConfig().getCloudEnv());
params.addProperty("query", query);
String responseContent = wxMaService.post(DATABASE_UPDATE_URL, params.toString());
return WxGsonBuilder.create().fromJson(responseContent, WxCloudDatabaseUpdateResult.class);
}
@Override
public WxCloudDatabaseUpdateResult databaseUpdate(String query) throws WxErrorException {
String cloudEnv = this.wxMaService.getWxMaConfig().getCloudEnv();
return databaseUpdate(cloudEnv, query);
}
@Override
public WxCloudDatabaseUpdateResult databaseUpdate(String env, String query) throws WxErrorException {
String response = this.wxMaService.post(DATABASE_UPDATE_URL, ImmutableMap.of("env", env, "query", query));
return WxGsonBuilder.create().fromJson(response, WxCloudDatabaseUpdateResult.class);
}
@Override
public WxCloudDatabaseQueryResult query(String collection, String whereJson, Map<String, String> orderBy,
Integer skip, Integer limit) throws WxErrorException {
if (StringUtils.isBlank(whereJson)) {
whereJson = "{}";
}
StringBuilder orderBySb = new StringBuilder();
if (null != orderBy && !orderBy.isEmpty()) {
for (Map.Entry<String, String> entry : orderBy.entrySet()) {
orderBySb.append(".orderBy('").append(entry.getKey()).append("', '").append(entry.getValue()).append("')");
}
}
if (null == limit) {
limit = 100;
}
if (null == skip) {
skip = 0;
}
String query = blankJoiner.join(
"db.collection('", collection, "')",
".where(", whereJson, ")", orderBySb.toString(), ".skip(", skip, ").limit(", limit, ").get()");
JsonObject params = new JsonObject();
params.addProperty("env", this.wxMaService.getWxMaConfig().getCloudEnv());
params.addProperty("query", query);
String responseContent = wxMaService.post(DATABASE_QUERY_URL, params.toString());
return WxGsonBuilder.create().fromJson(responseContent, WxCloudDatabaseQueryResult.class);
}
@Override
public WxCloudDatabaseQueryResult databaseQuery(String query) throws WxErrorException {
String cloudEnv = this.wxMaService.getWxMaConfig().getCloudEnv();
return databaseQuery(cloudEnv, query);
}
@Override
public WxCloudDatabaseQueryResult databaseQuery(String env, String query) throws WxErrorException {
String response = this.wxMaService.post(DATABASE_QUERY_URL, ImmutableMap.of("env", env, "query", query));
return WxGsonBuilder.create().fromJson(response, WxCloudDatabaseQueryResult.class);
}
@Override
public JsonArray databaseAggregate(String query) throws WxErrorException {
String cloudEnv = this.wxMaService.getWxMaConfig().getCloudEnv();
return databaseAggregate(cloudEnv, query);
}
@Override
public JsonArray databaseAggregate(String env, String query) throws WxErrorException {
String response = this.wxMaService.post(DATABASE_AGGREGATE_URL, ImmutableMap.of("env", env, "query", query));
return GsonParser.parse(response).get("data").getAsJsonArray();
}
@Override
public Long count(String collection, String whereJson) throws WxErrorException {
String query = blankJoiner.join(
"db.collection('", collection, "')",
".where(", whereJson, ").count()");
JsonObject params = new JsonObject();
params.addProperty("env", this.wxMaService.getWxMaConfig().getCloudEnv());
params.addProperty("query", query);
String responseContent = wxMaService.post(DATABASE_COUNT_URL, params.toString());
return GsonParser.parse(responseContent).get("count").getAsLong();
}
@Override
public Long databaseCount(String query) throws WxErrorException {
String cloudEnv = this.wxMaService.getWxMaConfig().getCloudEnv();
return databaseCount(cloudEnv, query);
}
@Override
public Long databaseCount(String env, String query) throws WxErrorException {
String response = this.wxMaService.post(DATABASE_COUNT_URL, ImmutableMap.of("env", env, "query", query));
return GsonParser.parse(response).get("count").getAsLong();
}
@Override
public void updateIndex(String collectionName, List<WxCloudDatabaseCreateIndexRequest> createIndexes,
List<String> dropIndexNames) throws WxErrorException {
String cloudEnv = this.wxMaService.getWxMaConfig().getCloudEnv();
updateIndex(cloudEnv, collectionName, createIndexes, dropIndexNames);
}
@Override
public void updateIndex(String env, String collectionName, List<WxCloudDatabaseCreateIndexRequest> createIndexes,
List<String> dropIndexNames) throws WxErrorException {
List<Map<String, String>> dropIndexes = Lists.newArrayList();
if (dropIndexNames != null) {
for (String index : dropIndexNames) {
dropIndexes.add(ImmutableMap.of("name", index));
}
}
this.wxMaService.post(UPDATE_INDEX_URL, ImmutableMap.of("env", env,
"collection_name", collectionName, "create_indexes", createIndexes, "drop_indexes", dropIndexes));
}
@Override
public Long databaseMigrateImport(String collectionName, String filePath, int fileType,
boolean stopOnError, int conflictMode) throws WxErrorException {
String cloudEnv = this.wxMaService.getWxMaConfig().getCloudEnv();
return databaseMigrateImport(cloudEnv, collectionName, filePath, fileType, stopOnError, conflictMode);
}
@Override
public Long databaseMigrateImport(String env, String collectionName, String filePath, int fileType,
boolean stopOnError, int conflictMode) throws WxErrorException {
JsonObject params = new JsonObject();
params.addProperty("env", env);
params.addProperty("collection_name", collectionName);
params.addProperty("file_path", filePath);
params.addProperty("file_type", fileType);
params.addProperty("stop_on_error", stopOnError);
params.addProperty("conflict_mode", conflictMode);
String response = this.wxMaService.post(DATABASE_MIGRATE_IMPORT_URL, params.toString());
return GsonParser.parse(response).get("job_id").getAsLong();
}
@Override
public Long databaseMigrateExport(String filePath, int fileType, String query) throws WxErrorException {
String cloudEnv = this.wxMaService.getWxMaConfig().getCloudEnv();
return databaseMigrateExport(cloudEnv, filePath, fileType, query);
}
@Override
public Long databaseMigrateExport(String env, String filePath, int fileType, String query) throws WxErrorException {
JsonObject params = new JsonObject();
params.addProperty("env", env);
params.addProperty("file_path", filePath);
params.addProperty("file_type", fileType);
params.addProperty("query", query);
String response = this.wxMaService.post(DATABASE_MIGRATE_EXPORT_URL, params.toString());
return GsonParser.parse(response).get("job_id").getAsLong();
}
@Override
public WxCloudCloudDatabaseMigrateQueryInfoResult databaseMigrateQueryInfo(Long jobId) throws WxErrorException {
String cloudEnv = this.wxMaService.getWxMaConfig().getCloudEnv();
return databaseMigrateQueryInfo(cloudEnv, jobId);
}
@Override
public WxCloudCloudDatabaseMigrateQueryInfoResult databaseMigrateQueryInfo(String env, Long jobId) throws WxErrorException {
String response = this.wxMaService.post(DATABASE_MIGRATE_QUERY_INFO_URL, ImmutableMap.of("env", env, "job_id",
jobId));
return WxGsonBuilder.create().fromJson(response, WxCloudCloudDatabaseMigrateQueryInfoResult.class);
}
@Override
public WxCloudUploadFileResult uploadFile(String path) throws WxErrorException {
String cloudEnv = this.wxMaService.getWxMaConfig().getCloudEnv();
return uploadFile(cloudEnv, path);
}
@Override
public WxCloudUploadFileResult uploadFile(String env, String path) throws WxErrorException {
String response = this.wxMaService.post(UPLOAD_FILE_URL, ImmutableMap.of("env", env, "path", path));
return WxGsonBuilder.create().fromJson(response, WxCloudUploadFileResult.class);
}
@Override
public WxCloudBatchDownloadFileResult batchDownloadFile(String[] fileIds, long[] maxAges) throws WxErrorException {
String cloudEnv = this.wxMaService.getWxMaConfig().getCloudEnv();
return batchDownloadFile(cloudEnv, fileIds, maxAges);
}
@Override
public WxCloudBatchDownloadFileResult batchDownloadFile(String env, String[] fileIds, long[] maxAges) throws WxErrorException {
List<Map<String, Serializable>> fileList = Lists.newArrayList();
int i = 0;
for (String fileId : fileIds) {
fileList.add(ImmutableMap.of("fileid", fileId, "max_age", (Serializable) maxAges[i++]));
}
String response = this.wxMaService.post(BATCH_DOWNLOAD_FILE_URL, ImmutableMap.of("env", env, "file_list", fileList));
return WxGsonBuilder.create().fromJson(response, WxCloudBatchDownloadFileResult.class);
}
@Override
public WxCloudBatchDeleteFileResult batchDeleteFile(String[] fileIds) throws WxErrorException {
String cloudEnv = this.wxMaService.getWxMaConfig().getCloudEnv();
return batchDeleteFile(cloudEnv, fileIds);
}
@Override
public WxCloudBatchDeleteFileResult batchDeleteFile(String env, String[] fileIds) throws WxErrorException {
String response = this.wxMaService.post(BATCH_DELETE_FILE_URL, ImmutableMap.of("env", env, "fileid_list", fileIds));
return WxGsonBuilder.create().fromJson(response, WxCloudBatchDeleteFileResult.class);
}
@Override
public WxCloudGetQcloudTokenResult getQcloudToken(long lifeSpan) throws WxErrorException {
String response = this.wxMaService.post(GET_QCLOUD_TOKEN_URL, ImmutableMap.of("lifespan", lifeSpan));
return WxGsonBuilder.create().fromJson(response, WxCloudGetQcloudTokenResult.class);
}
@Override
public void databaseCollectionAdd(String collectionName) throws WxErrorException {
String cloudEnv = this.wxMaService.getWxMaConfig().getCloudEnv();
databaseCollectionAdd(cloudEnv, collectionName);
}
@Override
public void databaseCollectionAdd(String env, String collectionName) throws WxErrorException {
this.wxMaService.post(DATABASE_COLLECTION_ADD_URL, ImmutableMap.of("env", env, "collection_name", collectionName));
}
@Override
public void databaseCollectionDelete(String collectionName) throws WxErrorException {
String cloudEnv = this.wxMaService.getWxMaConfig().getCloudEnv();
databaseCollectionDelete(cloudEnv, collectionName);
}
@Override
public void databaseCollectionDelete(String env, String collectionName) throws WxErrorException {
this.wxMaService.post(DATABASE_COLLECTION_DELETE_URL, ImmutableMap.of("env", env, "collection_name",
collectionName));
}
@Override
public WxCloudDatabaseCollectionGetResult databaseCollectionGet(Long limit, Long offset) throws WxErrorException {
String cloudEnv = this.wxMaService.getWxMaConfig().getCloudEnv();
return databaseCollectionGet(cloudEnv, limit, offset);
}
@Override
public WxCloudDatabaseCollectionGetResult databaseCollectionGet(String env, Long limit, Long offset) throws WxErrorException {
Map<String, Object> params = new HashMap<>(2);
params.put("env", env);
if (limit != null) {
params.put("limit", limit);
}
if (offset != null) {
params.put("offset", offset);
}
String response = this.wxMaService.post(DATABASE_COLLECTION_GET_URL, params);
return WxGsonBuilder.create().fromJson(response, WxCloudDatabaseCollectionGetResult.class);
}
@Override
public WxCloudSendSmsV2Result sendSmsV2(WxCloudSendSmsV2Request request) throws WxErrorException {
// 如果没有指定云环境ID,取默认云环境ID
if (request.getEnv() == null) {
String cloudEnv = this.wxMaService.getWxMaConfig().getCloudEnv();
request.setEnv(cloudEnv);
}
String response = this.wxMaService.post(SEND_SMS_V2_URL, request);
return WxGsonBuilder.create().fromJson(response, WxCloudSendSmsV2Result.class);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaComplaintServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaComplaintServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaComplaintService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.complaint.*;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.bean.CommonUploadParam;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.fs.FileUtils;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.UUID;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Complaint.*;
/**
* 小程序交易投诉接口实现
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* created on 2025-01-01
*/
@RequiredArgsConstructor
public class WxMaComplaintServiceImpl implements WxMaComplaintService {
private static final String JSON_CONTENT_TYPE = "application/json";
private final WxMaService wxMaService;
@Override
public WxMaComplaintResult queryComplaints(WxMaComplaintRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(QUERY_COMPLAINTS_URL, request.toJson());
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaComplaintResult.class);
}
@Override
public WxMaComplaintDetailResult getComplaint(WxMaComplaintDetailRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(GET_COMPLAINT_URL, request.toJson());
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaComplaintDetailResult.class);
}
@Override
public WxMaNegotiationHistoryResult queryNegotiationHistorys(WxMaNegotiationHistoryRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(QUERY_NEGOTIATION_HISTORY_URL, request.toJson());
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaNegotiationHistoryResult.class);
}
@Override
public WxMaComplaintNotifyUrlResult addComplaintNotifyUrl(WxMaComplaintNotifyUrlRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(ADD_COMPLAINT_NOTIFY_URL, request.toJson());
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaComplaintNotifyUrlResult.class);
}
@Override
public WxMaComplaintNotifyUrlResult getComplaintNotifyUrl() throws WxErrorException {
String responseContent = this.wxMaService.get(GET_COMPLAINT_NOTIFY_URL, null);
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaComplaintNotifyUrlResult.class);
}
@Override
public WxMaComplaintNotifyUrlResult updateComplaintNotifyUrl(WxMaComplaintNotifyUrlRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(UPDATE_COMPLAINT_NOTIFY_URL, request.toJson());
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaComplaintNotifyUrlResult.class);
}
@Override
public void deleteComplaintNotifyUrl() throws WxErrorException {
this.wxMaService.post(DELETE_COMPLAINT_NOTIFY_URL, "{}");
}
@Override
public void submitResponse(WxMaResponseRequest request) throws WxErrorException {
this.wxMaService.post(SUBMIT_RESPONSE_URL, request.toJson());
}
@Override
public void complete(WxMaCompleteRequest request) throws WxErrorException {
this.wxMaService.post(COMPLETE_COMPLAINT_URL, request.toJson());
}
@Override
public String uploadResponseImage(File imageFile) throws WxErrorException, IOException {
String result = this.wxMaService.upload(UPLOAD_RESPONSE_IMAGE_URL,
CommonUploadParam.fromFile("image", imageFile));
JsonObject jsonResult = WxMaGsonBuilder.create().fromJson(result, JsonObject.class);
return jsonResult.get("media_id").getAsString();
}
@Override
public String uploadResponseImage(InputStream inputStream, String fileName) throws WxErrorException, IOException {
try {
return this.uploadResponseImage(FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), fileName));
} catch (IOException e) {
throw new WxErrorException(WxError.builder().errorMsg(e.getMessage()).build(), e);
}
}
} | java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaMarketingServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaMarketingServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaMarketingService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.marketing.WxMaUserAction;
import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser;
import java.util.List;
/**
* @author <a href="https://github.com/184759547">184759547</a>
* 微信营销接口
* @since : 2021/12/28
*/
@Slf4j
@RequiredArgsConstructor
public class WxMaMarketingServiceImpl implements WxMaMarketingService {
private final WxMaService wxMaService;
private final String USER_ACTION_SETS_ADD = "https://api.weixin.qq.com/marketing/user_action_sets/add?version=v1.0";
private final String USER_ACTIONS_ADD = "https://api.weixin.qq.com/marketing/user_actions/add?version=v1.0";
@Override
public long addUserActionSets(String type, String name, String description) throws WxErrorException {
JsonObject json = new JsonObject();
json.addProperty("type", type);
json.addProperty("name", name);
json.addProperty("description", description);
String responseContent = wxMaService.post(USER_ACTION_SETS_ADD, json.toString());
JsonObject tmpJson = GsonParser.parse(responseContent);
return tmpJson.get("data").getAsJsonObject().get("user_action_set_id").getAsLong();
}
@Override
public String addUserAction(List<WxMaUserAction> actions, Long userActionSetId) throws WxErrorException {
return wxMaService.post(USER_ACTIONS_ADD, WxMaUserAction.listToJson(actions, userActionSetId));
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaProductOrderServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaProductOrderServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Product.Order.AFTER_SALE_ACCEPT_APPLY;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Product.Order.AFTER_SALE_REJECT_APPLY;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Product.Order.BATCH_GET_AFTER_SALE_ORDER;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Product.Order.GET_AFTER_SALE_ORDER;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Product.Order.PRODUCT_DELIVERY_SEND;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Product.Order.PRODUCT_ORDER_CHANGE_MERCHANT_NOTES_URL;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Product.Order.PRODUCT_ORDER_DETAIL_URL;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Product.Order.PRODUCT_ORDER_GET_LIST;
import cn.binarywang.wx.miniapp.api.WxMaProductOrderService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.product.WxMiniBatchGetAfterSaleOrderResponse;
import cn.binarywang.wx.miniapp.bean.product.WxMiniGetAfterSaleOrderResponse;
import cn.binarywang.wx.miniapp.bean.product.WxMiniOrderDeliveryRequest;
import cn.binarywang.wx.miniapp.bean.product.WxMinishopOrderDetailResponse;
import cn.binarywang.wx.miniapp.bean.product.WxMinishopOrderListResponse;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopBaseResponse;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonHelper;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
/**
* 小程序交易组件-标准版-订单服务
*
* @author boris 详情请见 : https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/ministore/minishopopencomponent/API/order/get_order_list.html
*/
@RequiredArgsConstructor
@Slf4j
public class WxMaProductOrderServiceImpl implements WxMaProductOrderService {
private final WxMaService wxMaService;
@Override
public WxMinishopOrderListResponse getOrderList(
String startCreateTime, String endCreateTime, String startUpdateTime,
String endUpdateTime, Integer status, Integer page, Integer pageSize, Integer source)
throws WxErrorException {
String responseContent = this.wxMaService
.post(PRODUCT_ORDER_GET_LIST, GsonHelper.buildJsonObject(
"start_create_time", startCreateTime, "end_create_time", endCreateTime,
"start_update_time", startUpdateTime, "end_update_time", endUpdateTime,
"status", status, "page", page, "page_size", pageSize, "source", source));
WxMinishopOrderListResponse response = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMinishopOrderListResponse.class);
if (response.getErrCode() != 0) {
throw new WxErrorException(new WxError(response.getErrCode(), response.getErrMsg()));
}
return response;
}
@Override
public WxMinishopOrderDetailResponse getOrderDetail(
Long orderId) throws WxErrorException {
String responseContent = this.wxMaService
.post(PRODUCT_ORDER_DETAIL_URL, GsonHelper.buildJsonObject(
"order_id", orderId));
WxMinishopOrderDetailResponse getDetailResponse = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMinishopOrderDetailResponse.class);
if (getDetailResponse.getErrCode() != 0) {
throw new WxErrorException(
new WxError(getDetailResponse.getErrCode(), getDetailResponse.getErrMsg()));
}
return getDetailResponse;
}
@Override
public void changeMerchantNotes(Long orderId, String merchantNotes) throws WxErrorException {
String responseContent = this.wxMaService
.post(PRODUCT_ORDER_CHANGE_MERCHANT_NOTES_URL, GsonHelper.buildJsonObject(
"order_id", orderId,"merchant_notes",merchantNotes));
WxMaShopBaseResponse changeResult = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMaShopBaseResponse.class);
if (changeResult.getErrCode() != 0) {
throw new WxErrorException(
new WxError(changeResult.getErrCode(), changeResult.getErrMsg()));
}
}
@Override
public WxMaShopBaseResponse deliverySend(WxMiniOrderDeliveryRequest request)
throws WxErrorException {
String response = this.wxMaService.post(PRODUCT_DELIVERY_SEND, request);
WxMaShopBaseResponse baseResponse = WxMaGsonBuilder.create()
.fromJson(response, WxMaShopBaseResponse.class);
if (baseResponse.getErrCode() != 0) {
throw new WxErrorException(
new WxError(baseResponse.getErrCode(), baseResponse.getErrMsg()));
}
return baseResponse;
}
@Override
public WxMiniGetAfterSaleOrderResponse getAfterSaleOrder(Long afterSaleOrderId)
throws WxErrorException {
String response = this.wxMaService.post(GET_AFTER_SALE_ORDER,
GsonHelper.buildJsonObject("after_sale_order_id", afterSaleOrderId));
WxMiniGetAfterSaleOrderResponse orderResponse = WxMaGsonBuilder.create()
.fromJson(response, WxMiniGetAfterSaleOrderResponse.class);
if (orderResponse.getErrCode() != 0) {
throw new WxErrorException(
new WxError(orderResponse.getErrCode(), orderResponse.getErrMsg()));
}
return orderResponse;
}
@Override
public WxMiniBatchGetAfterSaleOrderResponse batchGetAfterSaleOrder(
List<Long> afterSaleOrderIdList)
throws WxErrorException {
String response = this.wxMaService.post(BATCH_GET_AFTER_SALE_ORDER,
GsonHelper.buildJsonObject("after_sale_order_id_list", afterSaleOrderIdList));
WxMiniBatchGetAfterSaleOrderResponse orderResponse = WxMaGsonBuilder.create()
.fromJson(response, WxMiniBatchGetAfterSaleOrderResponse.class);
if (orderResponse.getAfterSaleOrderList() == null) {
throw new WxErrorException(
new WxError(orderResponse.getErrCode(), "售后查询不存在"));
}
return orderResponse;
}
@Override
public WxMaShopBaseResponse afterSaleAccept(Long orderId, Long addressId)
throws WxErrorException {
String response = this.wxMaService.post(AFTER_SALE_ACCEPT_APPLY,
GsonHelper.buildJsonObject("order_id", orderId, "address_id", addressId));
WxMaShopBaseResponse baseResponse = WxGsonBuilder.create()
.fromJson(response, WxMaShopBaseResponse.class);
if (baseResponse.getErrCode() != 0) {
throw new WxErrorException(
new WxError(baseResponse.getErrCode(), baseResponse.getErrMsg()));
}
return baseResponse;
}
@Override
public WxMaShopBaseResponse afterSaleReject(Long afterSaleOrderId, String rejectReason)
throws WxErrorException {
String response = this.wxMaService.post(AFTER_SALE_REJECT_APPLY,
GsonHelper.buildJsonObject("order_id", afterSaleOrderId, "reject_reason", rejectReason));
WxMaShopBaseResponse baseResponse = WxGsonBuilder.create()
.fromJson(response, WxMaShopBaseResponse.class);
if (baseResponse.getErrCode() != 0) {
throw new WxErrorException(
new WxError(baseResponse.getErrCode(), baseResponse.getErrMsg()));
}
return baseResponse;
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaLiveMemberServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaLiveMemberServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaLiveMemberService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Broadcast.Role;
import com.google.common.base.Joiner;
import com.google.gson.JsonArray;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonHelper;
import me.chanjar.weixin.common.util.json.GsonParser;
import java.util.HashMap;
import java.util.Map;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Broadcast.Role.LIST_BY_ROLE;
/**
* .
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* created on 2021-02-15
*/
@RequiredArgsConstructor
public class WxMaLiveMemberServiceImpl implements WxMaLiveMemberService {
private final WxMaService service;
@Override
public String addRole(String username, int role) throws WxErrorException {
return this.service.post(Role.ADD_ROLE,
GsonHelper.buildJsonObject("username", username, "role", role));
}
@Override
public String deleteRole(String username, int role) throws WxErrorException {
return this.service.post(Role.DELETE_ROLE,
GsonHelper.buildJsonObject("username", username, "role", role));
}
@Override
public JsonArray listByRole(Integer role, Integer offset, Integer limit, String keyword) throws WxErrorException {
Map<String, Object> params = new HashMap<>(8);
params.put("role", role);
params.put("offset", offset);
params.put("limit", limit);
params.put("keyword", keyword);
final String response = this.service.get(LIST_BY_ROLE, Joiner.on("&").withKeyValueSeparator("=").join(params));
return GsonParser.parse(response).getAsJsonArray("list");
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopAuditServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopAuditServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.WxMaShopAuditService;
import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopAuditBrandRequest;
import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopAuditCategoryRequest;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopAuditBrandResponse;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopAuditCategoryResponse;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopAuditResultResponse;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonHelper;
import me.chanjar.weixin.common.util.json.GsonParser;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Audit.*;
import static me.chanjar.weixin.common.api.WxConsts.ERR_CODE;
/**
* 小程序交易组件-接入商品前必需接口(审核相关接口)
*
* @author liming1019
* created on 2021/8/12
*/
@RequiredArgsConstructor
@Slf4j
public class WxMaShopAuditServiceImpl implements WxMaShopAuditService {
private final WxMaService wxMaService;
/**
* 上传品牌信息(品牌审核)
*
* @param request
* @return WxMaShopAuditBrandResponse
* @throws WxErrorException
*/
@Override
public WxMaShopAuditBrandResponse auditBrand(WxMaShopAuditBrandRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(AUDIT_BRAND, request);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopAuditBrandResponse.class);
}
/**
* 上传类目资质(类目审核)
*
* @param request
* @return
* @throws WxErrorException
*/
@Override
public WxMaShopAuditCategoryResponse auditCategory(WxMaShopAuditCategoryRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(AUDIT_CATEGORY, request);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopAuditCategoryResponse.class);
}
/**
* 获取审核结果
*
* @param auditId
* @return WxMaShopAuditResultResponse
* @throws WxErrorException
*/
@Override
public WxMaShopAuditResultResponse getAuditResult(String auditId) throws WxErrorException {
String responseContent = this.wxMaService.post(AUDIT_RESULT, GsonHelper.buildJsonObject("audit_id", auditId));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopAuditResultResponse.class);
}
/**
* 获取小程序提交过的入驻资质信息
*
* @param reqType
* @return JsonObject
* @throws WxErrorException
*/
@Override
public JsonObject getMiniappCertificate(int reqType) throws WxErrorException {
String responseContent = this.wxMaService.post(GET_MINIAPP_CERTIFICATE, GsonHelper.buildJsonObject("req_type", reqType));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(responseContent, JsonObject.class);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaCodeServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaCodeServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaCodeService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.code.*;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.BaseMediaDownloadRequestExecutor;
import me.chanjar.weixin.common.util.http.RequestExecutor;
import me.chanjar.weixin.common.util.json.GsonHelper;
import me.chanjar.weixin.common.util.json.GsonParser;
import org.apache.commons.lang3.StringUtils;
import java.io.File;
import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Code.*;
/**
* @author <a href="https://github.com/charmingoh">Charming</a>
* @since 2018-04-26 20:00
*/
@RequiredArgsConstructor
public class WxMaCodeServiceImpl implements WxMaCodeService {
private final WxMaService service;
@Override
public void commit(WxMaCodeCommitRequest commitRequest) throws WxErrorException {
this.service.post(COMMIT_URL, commitRequest.toJson());
}
@Override
public byte[] getQrCode(String path) throws WxErrorException {
String appId = this.service.getWxMaConfig().getAppid();
Path qrCodeFilePath = null;
try {
RequestExecutor<File, String> executor = BaseMediaDownloadRequestExecutor
.create(this.service.getRequestHttp(), Files.createTempDirectory("wxjava-ma-" + appId).toFile());
final StringBuilder url = new StringBuilder(GET_QRCODE_URL);
if (StringUtils.isNotBlank(path)) {
url.append("?path=").append(URLEncoder.encode(path, StandardCharsets.UTF_8.name()));
}
qrCodeFilePath = this.service.execute(executor, url.toString(), null).toPath();
return Files.readAllBytes(qrCodeFilePath);
} catch (IOException e) {
throw new WxErrorException(WxError.builder().errorMsg(e.getMessage()).build(), e);
} finally {
if (qrCodeFilePath != null) {
try {
// 及时删除二维码文件,避免积压过多缓存文件
Files.delete(qrCodeFilePath);
} catch (Exception ignored) {
}
}
}
}
@Override
public List<WxMaCodeSubmitAuditItem> getCategory() throws WxErrorException {
String responseContent = this.service.get(GET_CATEGORY_URL, null);
JsonObject jsonObject = GsonParser.parse(responseContent);
boolean hasCategoryList = jsonObject.has("category_list");
if (hasCategoryList) {
return WxMaGsonBuilder.create().fromJson(jsonObject.getAsJsonArray("category_list"),
new TypeToken<List<WxMaCodeSubmitAuditItem>>() {
}.getType());
} else {
return null;
}
}
@Override
public List<String> getPage() throws WxErrorException {
String responseContent = this.service.get(GET_PAGE_URL, null);
JsonObject jsonObject = GsonParser.parse(responseContent);
boolean hasPageList = jsonObject.has("page_list");
if (hasPageList) {
return WxMaGsonBuilder.create().fromJson(jsonObject.getAsJsonArray("page_list"),
new TypeToken<List<String>>() {
}.getType());
} else {
return null;
}
}
@Override
public long submitAudit(WxMaCodeSubmitAuditRequest auditRequest) throws WxErrorException {
String responseContent = this.service.post(SUBMIT_AUDIT_URL, auditRequest.toJson());
JsonObject jsonObject = GsonParser.parse(responseContent);
return GsonHelper.getLong(jsonObject, "auditid");
}
@Override
public WxMaCodeAuditStatus getAuditStatus(long auditId) throws WxErrorException {
JsonObject param = new JsonObject();
param.addProperty("auditid", auditId);
String responseContent = this.service.post(GET_AUDIT_STATUS_URL, param.toString());
return WxMaCodeAuditStatus.fromJson(responseContent);
}
@Override
public WxMaCodeAuditStatus getLatestAuditStatus() throws WxErrorException {
String responseContent = this.service.get(GET_LATEST_AUDIT_STATUS_URL, null);
return WxMaCodeAuditStatus.fromJson(responseContent);
}
@Override
public void release() throws WxErrorException {
this.service.post(RELEASE_URL, "{}");
}
@Override
public void changeVisitStatus(String action) throws WxErrorException {
JsonObject param = new JsonObject();
param.addProperty("action", action);
this.service.post(CHANGE_VISIT_STATUS_URL, param.toString());
}
@Override
public void revertCodeRelease() throws WxErrorException {
this.service.get(REVERT_CODE_RELEASE_URL, null);
}
@Override
public WxMaCodeVersionDistribution getSupportVersion() throws WxErrorException {
String responseContent = this.service.post(GET_SUPPORT_VERSION_URL, "{}");
return WxMaCodeVersionDistribution.fromJson(responseContent);
}
@Override
public WxMaCodeVersionInfo getVersionInfo() throws WxErrorException {
String responseContent = this.service.post(GET_VERSION_INFO_URL, "{}");
return WxMaCodeVersionInfo.fromJson(responseContent);
}
@Override
public void setSupportVersion(String version) throws WxErrorException {
JsonObject param = new JsonObject();
param.addProperty("version", version);
this.service.post(SET_SUPPORT_VERSION_URL, param.toString());
}
@Override
public void undoCodeAudit() throws WxErrorException {
this.service.get(UNDO_CODE_AUDIT_URL, null);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaUserServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaUserServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.WxMaUserService;
import cn.binarywang.wx.miniapp.bean.WxMaCode2VerifyInfoResult;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
import cn.binarywang.wx.miniapp.config.WxMaConfig;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import cn.binarywang.wx.miniapp.util.crypt.WxMaCryptUtils;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.SignUtils;
import me.chanjar.weixin.common.util.json.GsonParser;
import org.apache.commons.codec.digest.DigestUtils;
import java.util.Map;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.User.CODE_2_VERIFY_INFO_URL;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.User.GET_PHONE_NUMBER_URL;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.User.SET_USER_STORAGE;
/**
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
@RequiredArgsConstructor
public class WxMaUserServiceImpl implements WxMaUserService {
private static final String PHONE_INFO = "phone_info";
private final WxMaService service;
@Override
public WxMaJscode2SessionResult getSessionInfo(String jsCode) throws WxErrorException {
return service.jsCode2SessionInfo(jsCode);
}
@Override
public WxMaUserInfo getUserInfo(String sessionKey, String encryptedData, String ivStr) {
return WxMaUserInfo.fromJson(WxMaCryptUtils.decrypt(sessionKey, encryptedData, ivStr));
}
@Override
public void setUserStorage(Map<String, String> kvMap, String sessionKey, String openid) throws WxErrorException {
final WxMaConfig config = this.service.getWxMaConfig();
JsonObject param = new JsonObject();
JsonArray array = new JsonArray();
for (Map.Entry<String, String> e : kvMap.entrySet()) {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("key", e.getKey());
jsonObject.addProperty("value", e.getValue());
array.add(jsonObject);
}
param.add("kv_list", array);
String params = param.toString();
String signature = SignUtils.createHmacSha256Sign(params, sessionKey);
String url = String.format(SET_USER_STORAGE, config.getAppid(), signature, openid, "hmac_sha256");
this.service.post(url, params);
}
@Override
public WxMaPhoneNumberInfo getPhoneNoInfo(String sessionKey, String encryptedData, String ivStr) {
return WxMaPhoneNumberInfo.fromJson(WxMaCryptUtils.decrypt(sessionKey, encryptedData, ivStr));
}
@Override
public WxMaPhoneNumberInfo getPhoneNumber(String code) throws WxErrorException {
JsonObject param = new JsonObject();
param.addProperty("code", code);
String responseContent = this.service.post(GET_PHONE_NUMBER_URL, param.toString());
JsonObject response = GsonParser.parse(responseContent);
if (response.has(PHONE_INFO)) {
return WxMaGsonBuilder.create().fromJson(response.getAsJsonObject(PHONE_INFO),
WxMaPhoneNumberInfo.class);
}
return null;
}
@Override
public WxMaPhoneNumberInfo getPhoneNoInfo(String code) throws WxErrorException {
return this.getPhoneNumber(code);
}
@Override
public boolean checkUserInfo(String sessionKey, String rawData, String signature) {
final String generatedSignature = DigestUtils.sha1Hex(rawData + sessionKey);
return generatedSignature.equals(signature);
}
@Override
public WxMaCode2VerifyInfoResult getCode2VerifyInfo(String code, String checkcode) throws WxErrorException {
JsonObject param = new JsonObject();
param.addProperty("code", code);
param.addProperty("checkcode", checkcode);
String responseContent = this.service.post(CODE_2_VERIFY_INFO_URL, param.toString());
return WxMaCode2VerifyInfoResult.fromJson(responseContent);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaDeviceSubscribeServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaDeviceSubscribeServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaDeviceSubscribeService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.device.*;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import java.util.List;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.DeviceSubscribe.GET_SN_TICKET_URL;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.DeviceSubscribe.SEND_DEVICE_SUBSCRIBE_MSG_URL;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.DeviceSubscribe.CREATE_IOT_GROUP_ID_URL;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.DeviceSubscribe.GET_IOT_GROUP_INFO_URL;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.DeviceSubscribe.ADD_IOT_GROUP_DEVICE_URL;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.DeviceSubscribe.REMOVE_IOT_GROUP_DEVICE_URL;
/**
* 小程序设备订阅消息相关 API
* 文档:
*
* @author <a href="https://github.com/leejuncheng">JCLee</a>
* @since 2021-12-16 17:13:35
*/
@RequiredArgsConstructor
public class WxMaDeviceSubscribeServiceImpl implements WxMaDeviceSubscribeService {
private final WxMaService service;
@Override
public String getSnTicket(WxMaDeviceTicketRequest deviceTicketRequest) throws WxErrorException {
String responseContent = this.service.post(GET_SN_TICKET_URL, deviceTicketRequest.toJson());
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
String snTicket = jsonObject.get("sn_ticket").getAsString();
return snTicket;
}
@Override
public void sendDeviceSubscribeMsg(WxMaDeviceSubscribeMessageRequest deviceSubscribeMessageRequest) throws WxErrorException {
String responseContent = this.service.post(SEND_DEVICE_SUBSCRIBE_MSG_URL, deviceSubscribeMessageRequest.toJson());
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
}
@Override
public String createIotGroupId(WxMaCreateIotGroupIdRequest createIotGroupIdRequest) throws WxErrorException {
String responseContent = this.service.post(CREATE_IOT_GROUP_ID_URL, createIotGroupIdRequest.toJson());
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return jsonObject.get("group_id").getAsString();
}
@Override
public WxMaIotGroupDeviceInfoResponse getIotGroupInfo(WxMaGetIotGroupInfoRequest getIotGroupInfoRequest) throws WxErrorException {
String responseContent = this.service.post(GET_IOT_GROUP_INFO_URL, getIotGroupInfoRequest.toJson());
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxGsonBuilder.create().fromJson(responseContent, WxMaIotGroupDeviceInfoResponse.class);
}
@Override
public List<WxMaDeviceTicketRequest> addIotGroupDevice(WxMaIotGroupDeviceRequest request) throws WxErrorException {
String responseContent = this.service.post(ADD_IOT_GROUP_DEVICE_URL, request.toJson());
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(jsonObject.getAsJsonArray("device_list"), new TypeToken<List<WxMaDeviceTicketRequest>>() {
}.getType());
}
@Override
public List<WxMaDeviceTicketRequest> removeIotGroupDevice(WxMaIotGroupDeviceRequest request) throws WxErrorException {
String responseContent = this.service.post(REMOVE_IOT_GROUP_DEVICE_URL, request.toJson());
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaGsonBuilder.create().fromJson(jsonObject.getAsJsonArray("device_list"), new TypeToken<List<WxMaDeviceTicketRequest>>() {
}.getType());
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopPayServiceImpl.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopPayServiceImpl.java | package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.WxMaShopPayService;
import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopPayCreateOrderRequest;
import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopPayOrderRefundRequest;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopBaseResponse;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopPayCreateOrderResponse;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopPayGetOrderResponse;
import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonHelper;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Pay.*;
/**
* 小程序支付管理订单相关接口
*
* @author liming1019
*/
@RequiredArgsConstructor
@Slf4j
public class WxMaShopPayServiceImpl implements WxMaShopPayService {
private final WxMaService wxMaService;
@Override
public WxMaShopPayCreateOrderResponse createOrder(WxMaShopPayCreateOrderRequest request) throws WxErrorException {
String response = this.wxMaService.post(CREATE_ORDER, request);
return WxGsonBuilder.create().fromJson(response, WxMaShopPayCreateOrderResponse.class);
}
@Override
public WxMaShopPayGetOrderResponse getOrder(String tradeNo) throws WxErrorException {
JsonObject request = GsonHelper.buildJsonObject("trade_no", tradeNo);
String response = this.wxMaService.post(GET_ORDER, request);
return WxGsonBuilder.create().fromJson(response, WxMaShopPayGetOrderResponse.class);
}
@Override
public WxMaShopBaseResponse refundOrder(WxMaShopPayOrderRefundRequest request) throws WxErrorException {
String response = this.wxMaService.post(REFUND_ORDER, request);
return WxGsonBuilder.create().fromJson(response, WxMaShopBaseResponse.class);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/JoddHttpVodSingleUploadRequestExecutor.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/JoddHttpVodSingleUploadRequestExecutor.java | package cn.binarywang.wx.miniapp.executor;
import cn.binarywang.wx.miniapp.bean.vod.WxMaVodSingleFileUploadResult;
import jodd.http.HttpConnectionProvider;
import jodd.http.HttpRequest;
import jodd.http.HttpResponse;
import jodd.http.ProxyInfo;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.RequestHttp;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
/**
*
*/
public class JoddHttpVodSingleUploadRequestExecutor extends VodSingleUploadRequestExecutor<HttpConnectionProvider, ProxyInfo> {
public JoddHttpVodSingleUploadRequestExecutor(RequestHttp<HttpConnectionProvider, ProxyInfo> requestHttp, String mediaName, String mediaType, String coverType, File coverData, String sourceContext) {
super(requestHttp, mediaName, mediaType, coverType, coverData, sourceContext);
}
@Override
public WxMaVodSingleFileUploadResult execute(String uri, File file, WxType wxType) throws WxErrorException, IOException {
HttpRequest request = HttpRequest.post(uri);
if (requestHttp.getRequestHttpProxy() != null) {
requestHttp.getRequestHttpClient().useProxy(requestHttp.getRequestHttpProxy());
}
request.withConnectionProvider(requestHttp.getRequestHttpClient());
request.form("media_data", file);
request.form("media_name", mediaName);
request.form("media_type", mediaType);
if (coverType != null) {
request.form("cover_type", coverType);
}
if (coverData != null) {
request.form("cover_data", coverData);
}
if (sourceContext != null) {
request.form("source_context", sourceContext);
}
HttpResponse response = request.send();
response.charset(StandardCharsets.UTF_8.name());
String responseContent = response.bodyText();
WxError error = WxError.fromJson(responseContent, wxType);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
}
return WxMaVodSingleFileUploadResult.fromJson(responseContent);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/ApacheQrcodeBytesRequestExecutor.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/ApacheQrcodeBytesRequestExecutor.java | package cn.binarywang.wx.miniapp.executor;
import cn.binarywang.wx.miniapp.bean.AbstractWxMaQrcodeWrapper;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.apache.InputStreamResponseHandler;
import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler;
import org.apache.commons.io.IOUtils;
import org.apache.http.Header;
import org.apache.http.HttpHost;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import java.io.IOException;
import java.io.InputStream;
/**
* @author wenqiang
* @since 2020/12/25
*/
public class ApacheQrcodeBytesRequestExecutor extends QrcodeBytesRequestExecutor<CloseableHttpClient, HttpHost> {
public ApacheQrcodeBytesRequestExecutor(RequestHttp<CloseableHttpClient, HttpHost> requestHttp) {
super(requestHttp);
}
/**
* 执行http请求.
*
* @param uri uri
* @param qrcodeWrapper 数据
* @param wxType 微信模块类型
* @return 响应结果
* @throws WxErrorException 自定义异常
* @throws IOException io异常
*/
@Override
public byte[] execute(String uri, AbstractWxMaQrcodeWrapper qrcodeWrapper, WxType wxType) throws WxErrorException, IOException {
HttpPost httpPost = new HttpPost(uri);
if (requestHttp.getRequestHttpProxy() != null) {
httpPost.setConfig(
RequestConfig.custom().setProxy(requestHttp.getRequestHttpProxy()).build()
);
}
httpPost.setEntity(new StringEntity(qrcodeWrapper.toJson()));
try (final CloseableHttpResponse response = requestHttp.getRequestHttpClient().execute(httpPost);
final InputStream inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response)) {
Header[] contentTypeHeader = response.getHeaders("Content-Type");
if (contentTypeHeader != null && contentTypeHeader.length > 0
&& ContentType.APPLICATION_JSON.getMimeType()
.equals(ContentType.parse(contentTypeHeader[0].getValue()).getMimeType())) {
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
throw new WxErrorException(WxError.fromJson(responseContent, wxType));
}
return IOUtils.toByteArray(inputStream);
}
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/VodUploadPartRequestExecutor.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/VodUploadPartRequestExecutor.java | package cn.binarywang.wx.miniapp.executor;
import cn.binarywang.wx.miniapp.bean.vod.WxMaVodUploadPartResult;
import jodd.http.HttpConnectionProvider;
import jodd.http.ProxyInfo;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.RequestExecutor;
import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.ResponseHandler;
import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo;
import okhttp3.OkHttpClient;
import java.io.File;
import java.io.IOException;
/**
*/
public abstract class VodUploadPartRequestExecutor<H, P> implements RequestExecutor<WxMaVodUploadPartResult, File> {
protected RequestHttp<H, P> requestHttp;
protected String uploadId;
protected Integer partNumber;
protected Integer resourceType;
public VodUploadPartRequestExecutor(RequestHttp<H, P> requestHttp, String uploadId, Integer partNumber, Integer resourceType) {
this.requestHttp = requestHttp;
this.uploadId = uploadId;
this.partNumber = partNumber;
this.resourceType = resourceType;
}
@SuppressWarnings("unchecked")
public static RequestExecutor<WxMaVodUploadPartResult, File> create(RequestHttp<?, ?> requestHttp, String uploadId, Integer partNumber, Integer resourceType) {
switch (requestHttp.getRequestType()) {
case APACHE_HTTP:
return new ApacheVodUploadPartRequestExecutor(
(RequestHttp<org.apache.http.impl.client.CloseableHttpClient, org.apache.http.HttpHost>) requestHttp,
uploadId, partNumber, resourceType);
case JODD_HTTP:
return new JoddHttpVodUploadPartRequestExecutor((RequestHttp<HttpConnectionProvider, ProxyInfo>) requestHttp, uploadId, partNumber, resourceType);
case OK_HTTP:
return new OkHttpVodUploadPartRequestExecutor((RequestHttp<OkHttpClient, OkHttpProxyInfo>) requestHttp, uploadId, partNumber, resourceType);
case HTTP_COMPONENTS:
return new HttpComponentsVodUploadPartRequestExecutor(
(RequestHttp<org.apache.hc.client5.http.impl.classic.CloseableHttpClient, org.apache.hc.core5.http.HttpHost>) requestHttp,
uploadId, partNumber, resourceType);
default:
throw new IllegalArgumentException("不支持的http执行器类型:" + requestHttp.getRequestType());
}
}
@Override
public void execute(String uri, File data, ResponseHandler<WxMaVodUploadPartResult> handler, WxType wxType) throws WxErrorException, IOException {
handler.handle(this.execute(uri, data, wxType));
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/JoddHttpQrcodeFileRequestExecutor.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/JoddHttpQrcodeFileRequestExecutor.java | package cn.binarywang.wx.miniapp.executor;
import cn.binarywang.wx.miniapp.bean.AbstractWxMaQrcodeWrapper;
import jodd.http.HttpConnectionProvider;
import jodd.http.HttpRequest;
import jodd.http.HttpResponse;
import jodd.http.ProxyInfo;
import jodd.net.MimeTypes;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.fs.FileUtils;
import me.chanjar.weixin.common.util.http.RequestHttp;
import org.apache.commons.lang3.StringUtils;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.util.UUID;
/**
* @author wenqiang
* @since 2020/12/25
*/
public class JoddHttpQrcodeFileRequestExecutor extends QrcodeRequestExecutor<HttpConnectionProvider, ProxyInfo> {
private final String filePath;
public JoddHttpQrcodeFileRequestExecutor(RequestHttp<HttpConnectionProvider, ProxyInfo> requestHttp, String filePath) {
super(requestHttp);
this.filePath = filePath;
}
/**
* 执行http请求.
*
* @param uri uri
* @param qrcodeWrapper 数据
* @param wxType 微信模块类型
* @return 响应结果
* @throws WxErrorException 自定义异常
* @throws IOException io异常
*/
@Override
public File execute(String uri, AbstractWxMaQrcodeWrapper qrcodeWrapper, WxType wxType) throws WxErrorException, IOException {
HttpRequest request = HttpRequest.get(uri);
if (requestHttp.getRequestHttpProxy() != null) {
requestHttp.getRequestHttpClient().useProxy(requestHttp.getRequestHttpProxy());
}
request.withConnectionProvider(requestHttp.getRequestHttpClient());
HttpResponse response = request.send();
response.charset(StandardCharsets.UTF_8.name());
String contentTypeHeader = response.header("Content-Type");
if (MimeTypes.MIME_APPLICATION_JSON.equals(contentTypeHeader)) {
String responseContent = response.bodyText();
throw new WxErrorException(WxError.fromJson(responseContent, wxType));
}
try (InputStream inputStream = new ByteArrayInputStream(response.bodyBytes())) {
if (StringUtils.isBlank(filePath)) {
return FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), "jpg");
}
return FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), "jpg", Paths.get(filePath).toFile());
}
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/OkHttpQrcodeBytesRequestExecutor.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/OkHttpQrcodeBytesRequestExecutor.java | package cn.binarywang.wx.miniapp.executor;
import cn.binarywang.wx.miniapp.bean.AbstractWxMaQrcodeWrapper;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo;
import okhttp3.*;
import org.apache.commons.io.IOUtils;
import java.io.IOException;
import java.io.InputStream;
/**
* @author wenqiang
* @since 2020/12/25
*/
public class OkHttpQrcodeBytesRequestExecutor extends QrcodeBytesRequestExecutor<OkHttpClient, OkHttpProxyInfo> {
public OkHttpQrcodeBytesRequestExecutor(RequestHttp<OkHttpClient, OkHttpProxyInfo> requestHttp) {
super(requestHttp);
}
/**
* 执行http请求.
*
* @param uri uri
* @param qrcodeWrapper 数据
* @param wxType 微信模块类型
* @return 响应结果
* @throws WxErrorException 自定义异常
* @throws IOException io异常
*/
@Override
public byte[] execute(String uri, AbstractWxMaQrcodeWrapper qrcodeWrapper, WxType wxType) throws WxErrorException, IOException {
RequestBody body = RequestBody.Companion.create(qrcodeWrapper.toJson(), MediaType.parse("application/json; charset=utf-8"));
Request request = new Request.Builder().url(uri).post(body).build();
Response response = requestHttp.getRequestHttpClient().newCall(request).execute();
String contentTypeHeader = response.header("Content-Type");
if (null != contentTypeHeader && contentTypeHeader.startsWith("application/json")) {
String responseContent = response.body().string();
throw new WxErrorException(WxError.fromJson(responseContent, wxType));
}
try (InputStream inputStream = response.body().byteStream()) {
return IOUtils.toByteArray(inputStream);
}
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/OkHttpVodUploadPartRequestExecutor.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/OkHttpVodUploadPartRequestExecutor.java | package cn.binarywang.wx.miniapp.executor;
import cn.binarywang.wx.miniapp.bean.vod.WxMaVodUploadPartResult;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo;
import okhttp3.*;
import java.io.File;
import java.io.IOException;
/**
*
*/
public class OkHttpVodUploadPartRequestExecutor extends VodUploadPartRequestExecutor<OkHttpClient, OkHttpProxyInfo> {
public OkHttpVodUploadPartRequestExecutor(RequestHttp<OkHttpClient, OkHttpProxyInfo> requestHttp, String uploadId, Integer partNumber, Integer resourceType) {
super(requestHttp, uploadId, partNumber, resourceType);
}
@Override
public WxMaVodUploadPartResult execute(String uri, File file, WxType wxType) throws WxErrorException, IOException {
MultipartBody.Builder bodyBuilder = new MultipartBody.Builder()
.setType(MediaType.parse("multipart/form-data"))
.addFormDataPart("data",
file.getName(),
RequestBody.create(MediaType.parse("application/octet-stream"), file));
bodyBuilder.addFormDataPart("upload_id", uploadId)
.addFormDataPart("part_number", String.valueOf(this.partNumber))
.addFormDataPart("resource_type", String.valueOf(this.resourceType));
Request request = new Request.Builder().url(uri).post(bodyBuilder.build()).build();
Response response = requestHttp.getRequestHttpClient().newCall(request).execute();
String responseContent = response.body().string();
WxError error = WxError.fromJson(responseContent, wxType);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
}
return WxMaVodUploadPartResult.fromJson(responseContent);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/OkHttpQrcodeFileRequestExecutor.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/OkHttpQrcodeFileRequestExecutor.java | package cn.binarywang.wx.miniapp.executor;
import cn.binarywang.wx.miniapp.bean.AbstractWxMaQrcodeWrapper;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.fs.FileUtils;
import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo;
import okhttp3.*;
import org.apache.commons.lang3.StringUtils;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Paths;
import java.util.UUID;
/**
* @author wenqiang
* @since 2020/12/25
*/
public class OkHttpQrcodeFileRequestExecutor extends QrcodeRequestExecutor<OkHttpClient, OkHttpProxyInfo> {
private final String filePath;
public OkHttpQrcodeFileRequestExecutor(RequestHttp<OkHttpClient, OkHttpProxyInfo> requestHttp, String filePath) {
super(requestHttp);
this.filePath = filePath;
}
/**
* 执行http请求.
*
* @param uri uri
* @param qrcodeWrapper 数据
* @param wxType 微信模块类型
* @return 响应结果
* @throws WxErrorException 自定义异常
* @throws IOException io异常
*/
@Override
public File execute(String uri, AbstractWxMaQrcodeWrapper qrcodeWrapper, WxType wxType) throws WxErrorException, IOException {
RequestBody body = RequestBody.Companion.create(qrcodeWrapper.toJson(), MediaType.parse("application/json; charset=utf-8"));
Request request = new Request.Builder().url(uri).post(body).build();
Response response = requestHttp.getRequestHttpClient().newCall(request).execute();
String contentTypeHeader = response.header("Content-Type");
if (null != contentTypeHeader && contentTypeHeader.startsWith("application/json")) {
String responseContent = response.body().string();
throw new WxErrorException(WxError.fromJson(responseContent, wxType));
}
try (InputStream inputStream = response.body().byteStream()) {
if (StringUtils.isBlank(filePath)) {
return FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), "jpg");
}
return FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), "jpg", Paths.get(filePath).toFile());
}
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/ApiSignaturePostRequestExecutor.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/ApiSignaturePostRequestExecutor.java | package cn.binarywang.wx.miniapp.executor;
import cn.binarywang.wx.miniapp.bean.WxMaApiResponse;
import jodd.http.HttpConnectionProvider;
import jodd.http.ProxyInfo;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.RequestExecutor;
import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.ResponseHandler;
import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo;
import okhttp3.OkHttpClient;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.rmi.RemoteException;
import java.util.Map;
public abstract class ApiSignaturePostRequestExecutor<H, P>
implements RequestExecutor<WxMaApiResponse, WxMaApiResponse> {
protected RequestHttp<H, P> requestHttp;
public ApiSignaturePostRequestExecutor(RequestHttp<H, P> requestHttp) {
this.requestHttp = requestHttp;
}
@Override
public WxMaApiResponse execute(String uri, WxMaApiResponse data, WxType wxType)
throws WxErrorException, IOException {
throw new RemoteException("method not implemented yet.");
}
@Override
public void execute(
String uri, WxMaApiResponse data, ResponseHandler<WxMaApiResponse> handler, WxType wxType)
throws WxErrorException, IOException {
throw new RemoteException("method not implemented yet.");
}
public abstract WxMaApiResponse execute(
String uri, Map<String, String> headers, String data, WxType wxType)
throws WxErrorException, IOException;
@NotNull
public WxMaApiResponse handleResponse(
WxType wxType, String responseContent, Map<String, String> headers) throws WxErrorException {
if (responseContent.isEmpty()) {
throw new WxErrorException("无响应内容");
}
WxError error = WxError.fromJson(responseContent, wxType);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
}
WxMaApiResponse response = new WxMaApiResponse();
response.setContent(responseContent);
response.setHeaders(headers);
return response;
}
@SuppressWarnings("unchecked")
public static ApiSignaturePostRequestExecutor<?, ?> create(RequestHttp<?, ?> requestHttp) {
switch (requestHttp.getRequestType()) {
case APACHE_HTTP:
return new ApacheApiSignaturePostRequestExecutor(
(RequestHttp<org.apache.http.impl.client.CloseableHttpClient, org.apache.http.HttpHost>) requestHttp);
case JODD_HTTP:
return new JoddApiSignaturePostRequestExecutor((RequestHttp<HttpConnectionProvider, ProxyInfo>) requestHttp);
case OK_HTTP:
return new OkHttpApiSignaturePostRequestExecutor((RequestHttp<OkHttpClient, OkHttpProxyInfo>) requestHttp);
case HTTP_COMPONENTS:
return new HttpComponentsApiSignaturePostRequestExecutor(
(RequestHttp<org.apache.hc.client5.http.impl.classic.CloseableHttpClient, org.apache.hc.core5.http.HttpHost>) requestHttp);
default:
throw new IllegalArgumentException("不支持的http执行器类型:" + requestHttp.getRequestType());
}
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/ApacheUploadAuthMaterialRequestExecutor.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/ApacheUploadAuthMaterialRequestExecutor.java | package cn.binarywang.wx.miniapp.executor;
import cn.binarywang.wx.miniapp.bean.WxMaUploadAuthMaterialResult;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import java.io.File;
import java.io.IOException;
/**
* @author penhuozhu
* @since 2024/01/07
*/
public class ApacheUploadAuthMaterialRequestExecutor extends UploadAuthMaterialRequestExecutor<CloseableHttpClient, HttpHost> {
public ApacheUploadAuthMaterialRequestExecutor(RequestHttp<CloseableHttpClient, HttpHost> requestHttp) {
super(requestHttp);
}
@Override
public WxMaUploadAuthMaterialResult execute(String uri, File file, WxType wxType) throws WxErrorException, IOException {
HttpPost httpPost = new HttpPost(uri);
if (requestHttp.getRequestHttpProxy() != null) {
RequestConfig config = RequestConfig.custom().setProxy(requestHttp.getRequestHttpProxy()).build();
httpPost.setConfig(config);
}
if (file != null) {
HttpEntity entity = MultipartEntityBuilder
.create()
.addBinaryBody("media", file)
.setMode(HttpMultipartMode.RFC6532)
.build();
httpPost.setEntity(entity);
}
String responseContent = requestHttp.getRequestHttpClient().execute(httpPost, Utf8ResponseHandler.INSTANCE);
WxError error = WxError.fromJson(responseContent, wxType);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
}
return WxMaUploadAuthMaterialResult.fromJson(responseContent);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/UploadAuthMaterialRequestExecutor.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/UploadAuthMaterialRequestExecutor.java | package cn.binarywang.wx.miniapp.executor;
import cn.binarywang.wx.miniapp.bean.WxMaUploadAuthMaterialResult;
import jodd.http.HttpConnectionProvider;
import jodd.http.ProxyInfo;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.RequestExecutor;
import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.ResponseHandler;
import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo;
import okhttp3.OkHttpClient;
import java.io.File;
import java.io.IOException;
/**
* 小程序认证上传补充材料
* 上传媒体文件请求执行器.
* 请求的参数是File, 返回的结果是String
*
* @author penhuozhu
* @since 2024/01/07
*/
public abstract class UploadAuthMaterialRequestExecutor<H, P> implements RequestExecutor<WxMaUploadAuthMaterialResult, File> {
protected RequestHttp<H, P> requestHttp;
public UploadAuthMaterialRequestExecutor(RequestHttp<H, P> requestHttp) {
this.requestHttp = requestHttp;
}
@Override
public void execute(String uri, File data, ResponseHandler<WxMaUploadAuthMaterialResult> handler, WxType wxType) throws WxErrorException, IOException {
handler.handle(this.execute(uri, data, wxType));
}
@SuppressWarnings("unchecked")
public static RequestExecutor<WxMaUploadAuthMaterialResult, File> create(RequestHttp<?, ?> requestHttp) {
switch (requestHttp.getRequestType()) {
case APACHE_HTTP:
return new ApacheUploadAuthMaterialRequestExecutor(
(RequestHttp<org.apache.http.impl.client.CloseableHttpClient, org.apache.http.HttpHost>) requestHttp);
case JODD_HTTP:
return new JoddHttpUploadAuthMaterialRequestExecutor((RequestHttp<HttpConnectionProvider, ProxyInfo>) requestHttp);
case OK_HTTP:
return new OkHttpUploadAuthMaterialRequestExecutor((RequestHttp<OkHttpClient, OkHttpProxyInfo>) requestHttp);
case HTTP_COMPONENTS:
return new HttpComponentsUploadAuthMaterialRequestExecutor(
(RequestHttp<org.apache.hc.client5.http.impl.classic.CloseableHttpClient, org.apache.hc.core5.http.HttpHost>) requestHttp);
default:
throw new IllegalArgumentException("不支持的http执行器类型:" + requestHttp.getRequestType());
}
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/ApacheQrcodeFileRequestExecutor.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/ApacheQrcodeFileRequestExecutor.java | package cn.binarywang.wx.miniapp.executor;
import cn.binarywang.wx.miniapp.bean.AbstractWxMaQrcodeWrapper;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.fs.FileUtils;
import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.apache.InputStreamResponseHandler;
import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.Header;
import org.apache.http.HttpHost;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Paths;
import java.util.UUID;
/**
* @author wenqiang
* @since 2020/12/25
*/
public class ApacheQrcodeFileRequestExecutor extends QrcodeRequestExecutor<CloseableHttpClient, HttpHost> {
private final String filePath;
public ApacheQrcodeFileRequestExecutor(RequestHttp<CloseableHttpClient, HttpHost> requestHttp, String filePath) {
super(requestHttp);
this.filePath = filePath;
}
/**
* 执行http请求.
*
* @param uri uri
* @param qrcodeWrapper 数据
* @param wxType 微信模块类型
* @return 响应结果
* @throws WxErrorException 自定义异常
* @throws IOException io异常
*/
@Override
public File execute(String uri, AbstractWxMaQrcodeWrapper qrcodeWrapper, WxType wxType) throws WxErrorException, IOException {
HttpPost httpPost = new HttpPost(uri);
if (requestHttp.getRequestHttpProxy() != null) {
httpPost.setConfig(
RequestConfig.custom().setProxy(requestHttp.getRequestHttpProxy()).build()
);
}
httpPost.setEntity(new StringEntity(qrcodeWrapper.toJson(), ContentType.APPLICATION_JSON));
try (final CloseableHttpResponse response = requestHttp.getRequestHttpClient().execute(httpPost);
final InputStream inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response)) {
Header[] contentTypeHeader = response.getHeaders("Content-Type");
if (contentTypeHeader != null && contentTypeHeader.length > 0
&& ContentType.APPLICATION_JSON.getMimeType()
.equals(ContentType.parse(contentTypeHeader[0].getValue()).getMimeType())) {
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
throw new WxErrorException(WxError.fromJson(responseContent, wxType));
}
if (StringUtils.isBlank(filePath)) {
return FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), "jpg");
}
return FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), "jpg", Paths.get(filePath).toFile());
}
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/JoddHttpVodUploadPartRequestExecutor.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/JoddHttpVodUploadPartRequestExecutor.java | package cn.binarywang.wx.miniapp.executor;
import cn.binarywang.wx.miniapp.bean.vod.WxMaVodUploadPartResult;
import jodd.http.HttpConnectionProvider;
import jodd.http.HttpRequest;
import jodd.http.HttpResponse;
import jodd.http.ProxyInfo;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.RequestHttp;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
/**
*
*/
public class JoddHttpVodUploadPartRequestExecutor extends VodUploadPartRequestExecutor<HttpConnectionProvider, ProxyInfo> {
public JoddHttpVodUploadPartRequestExecutor(RequestHttp<HttpConnectionProvider, ProxyInfo> requestHttp, String uploadId, Integer partNumber, Integer resourceType) {
super(requestHttp, uploadId, partNumber, resourceType);
}
@Override
public WxMaVodUploadPartResult execute(String uri, File file, WxType wxType) throws WxErrorException, IOException {
HttpRequest request = HttpRequest.post(uri);
if (requestHttp.getRequestHttpProxy() != null) {
requestHttp.getRequestHttpClient().useProxy(requestHttp.getRequestHttpProxy());
}
request.withConnectionProvider(requestHttp.getRequestHttpClient());
request.form("data", file);
request.form("upload_id", uploadId);
request.form("part_number", partNumber);
request.form("resource_type", resourceType);
HttpResponse response = request.send();
response.charset(StandardCharsets.UTF_8.name());
String responseContent = response.bodyText();
WxError error = WxError.fromJson(responseContent, wxType);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
}
return WxMaVodUploadPartResult.fromJson(responseContent);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/OkHttpUploadAuthMaterialRequestExecutor.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/OkHttpUploadAuthMaterialRequestExecutor.java | package cn.binarywang.wx.miniapp.executor;
import cn.binarywang.wx.miniapp.bean.WxMaUploadAuthMaterialResult;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo;
import okhttp3.*;
import java.io.File;
import java.io.IOException;
/**
* @author penhuozhu
* @since 2024/01/07
*/
public class OkHttpUploadAuthMaterialRequestExecutor extends UploadAuthMaterialRequestExecutor<OkHttpClient, OkHttpProxyInfo> {
public OkHttpUploadAuthMaterialRequestExecutor(RequestHttp<OkHttpClient, OkHttpProxyInfo> requestHttp) {
super(requestHttp);
}
@Override
public WxMaUploadAuthMaterialResult execute(String uri, File file, WxType wxType) throws WxErrorException, IOException {
RequestBody body = new MultipartBody.Builder()
.setType(MediaType.parse("multipart/form-data"))
.addFormDataPart("media",
file.getName(),
RequestBody.create(MediaType.parse("application/octet-stream"), file))
.build();
Request request = new Request.Builder().url(uri).post(body).build();
Response response = requestHttp.getRequestHttpClient().newCall(request).execute();
String responseContent = response.body().string();
WxError error = WxError.fromJson(responseContent, wxType);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
}
return WxMaUploadAuthMaterialResult.fromJson(responseContent);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/HttpComponentsUploadAuthMaterialRequestExecutor.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/HttpComponentsUploadAuthMaterialRequestExecutor.java | package cn.binarywang.wx.miniapp.executor;
import cn.binarywang.wx.miniapp.bean.WxMaUploadAuthMaterialResult;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.hc.Utf8ResponseHandler;
import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.entity.mime.HttpMultipartMode;
import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.HttpHost;
import java.io.File;
import java.io.IOException;
/**
* @author altusea
*/
public class HttpComponentsUploadAuthMaterialRequestExecutor extends UploadAuthMaterialRequestExecutor<CloseableHttpClient, HttpHost> {
public HttpComponentsUploadAuthMaterialRequestExecutor(RequestHttp<CloseableHttpClient, HttpHost> requestHttp) {
super(requestHttp);
}
@Override
public WxMaUploadAuthMaterialResult execute(String uri, File file, WxType wxType) throws WxErrorException, IOException {
HttpPost httpPost = new HttpPost(uri);
if (requestHttp.getRequestHttpProxy() != null) {
RequestConfig config = RequestConfig.custom().setProxy(requestHttp.getRequestHttpProxy()).build();
httpPost.setConfig(config);
}
if (file != null) {
HttpEntity entity = MultipartEntityBuilder
.create()
.addBinaryBody("media", file)
.setMode(HttpMultipartMode.EXTENDED)
.build();
httpPost.setEntity(entity);
}
String responseContent = requestHttp.getRequestHttpClient().execute(httpPost, Utf8ResponseHandler.INSTANCE);
WxError error = WxError.fromJson(responseContent, wxType);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
}
return WxMaUploadAuthMaterialResult.fromJson(responseContent);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/VodSingleUploadRequestExecutor.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/VodSingleUploadRequestExecutor.java | package cn.binarywang.wx.miniapp.executor;
import cn.binarywang.wx.miniapp.bean.vod.WxMaVodSingleFileUploadResult;
import jodd.http.HttpConnectionProvider;
import jodd.http.ProxyInfo;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.RequestExecutor;
import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.ResponseHandler;
import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo;
import okhttp3.OkHttpClient;
import java.io.File;
import java.io.IOException;
/**
* 小程序 提审素材上传接口
* 上传媒体文件请求执行器.
* 请求的参数是File, 返回的结果是String
*
* @author yangyh22
* @since 2020/11/14
*/
public abstract class VodSingleUploadRequestExecutor<H, P> implements RequestExecutor<WxMaVodSingleFileUploadResult, File> {
protected RequestHttp<H, P> requestHttp;
protected String mediaName;
protected String mediaType;
protected String coverType;
protected String sourceContext;
protected File coverData;
public VodSingleUploadRequestExecutor(RequestHttp<H, P> requestHttp, String mediaName, String mediaType, String coverType, File coverData, String sourceContext) {
this.requestHttp = requestHttp;
this.mediaName = mediaName;
this.mediaType = mediaType;
this.coverType = coverType;
this.coverData = coverData;
this.sourceContext = sourceContext;
}
@SuppressWarnings("unchecked")
public static RequestExecutor<WxMaVodSingleFileUploadResult, File> create(RequestHttp<?, ?> requestHttp, String mediaName, String mediaType, String coverType, File coverData, String sourceContext) {
switch (requestHttp.getRequestType()) {
case APACHE_HTTP:
return new ApacheVodSingleUploadRequestExecutor(
(RequestHttp<org.apache.http.impl.client.CloseableHttpClient, org.apache.http.HttpHost>) requestHttp,
mediaName, mediaType, coverType, coverData, sourceContext);
case JODD_HTTP:
return new JoddHttpVodSingleUploadRequestExecutor((RequestHttp<HttpConnectionProvider, ProxyInfo>) requestHttp, mediaName, mediaType, coverType, coverData, sourceContext);
case OK_HTTP:
return new OkHttpVodSingleUploadRequestExecutor(
(RequestHttp<OkHttpClient, OkHttpProxyInfo>) requestHttp, mediaName, mediaType, coverType, coverData, sourceContext);
case HTTP_COMPONENTS:
return new HttpComponentsVodSingleUploadRequestExecutor(
(RequestHttp<org.apache.hc.client5.http.impl.classic.CloseableHttpClient, org.apache.hc.core5.http.HttpHost>) requestHttp,
mediaName, mediaType, coverType, coverData, sourceContext);
default:
throw new IllegalArgumentException("不支持的http执行器类型:" + requestHttp.getRequestType());
}
}
@Override
public void execute(String uri, File data, ResponseHandler<WxMaVodSingleFileUploadResult> handler, WxType wxType) throws WxErrorException, IOException {
handler.handle(this.execute(uri, data, wxType));
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/HttpComponentsVodUploadPartRequestExecutor.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/HttpComponentsVodUploadPartRequestExecutor.java | package cn.binarywang.wx.miniapp.executor;
import cn.binarywang.wx.miniapp.bean.vod.WxMaVodUploadPartResult;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.hc.Utf8ResponseHandler;
import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.entity.mime.HttpMultipartMode;
import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.core5.http.HttpHost;
import java.io.File;
import java.io.IOException;
public class HttpComponentsVodUploadPartRequestExecutor extends VodUploadPartRequestExecutor<CloseableHttpClient, HttpHost> {
public HttpComponentsVodUploadPartRequestExecutor(RequestHttp<CloseableHttpClient, HttpHost> requestHttp, String uploadId, Integer partNumber, Integer resourceType) {
super(requestHttp, uploadId, partNumber, resourceType);
}
@Override
public WxMaVodUploadPartResult execute(String uri, File file, WxType wxType) throws WxErrorException, IOException {
HttpPost httpPost = new HttpPost(uri);
if (requestHttp.getRequestHttpProxy() != null) {
RequestConfig config = RequestConfig.custom().setProxy(requestHttp.getRequestHttpProxy()).build();
httpPost.setConfig(config);
}
if (file != null) {
MultipartEntityBuilder entityBuilder = MultipartEntityBuilder
.create()
.setMode(HttpMultipartMode.EXTENDED)
.addTextBody("upload_id", uploadId)
.addTextBody("part_number", String.valueOf(partNumber))
.addTextBody("resource_type", String.valueOf(resourceType))
.addBinaryBody("data", file);
httpPost.setEntity(entityBuilder.build());
}
String responseContent = requestHttp.getRequestHttpClient().execute(httpPost, Utf8ResponseHandler.INSTANCE);
WxError error = WxError.fromJson(responseContent, wxType);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
}
return WxMaVodUploadPartResult.fromJson(responseContent);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/JoddHttpUploadAuthMaterialRequestExecutor.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/JoddHttpUploadAuthMaterialRequestExecutor.java | package cn.binarywang.wx.miniapp.executor;
import cn.binarywang.wx.miniapp.bean.WxMaUploadAuthMaterialResult;
import jodd.http.HttpConnectionProvider;
import jodd.http.HttpRequest;
import jodd.http.HttpResponse;
import jodd.http.ProxyInfo;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.RequestHttp;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
/**
* @author penhuozhu
* @since 2024/01/07
*/
public class JoddHttpUploadAuthMaterialRequestExecutor extends UploadAuthMaterialRequestExecutor<HttpConnectionProvider, ProxyInfo> {
public JoddHttpUploadAuthMaterialRequestExecutor(RequestHttp<HttpConnectionProvider, ProxyInfo> requestHttp) {
super(requestHttp);
}
@Override
public WxMaUploadAuthMaterialResult execute(String uri, File file, WxType wxType) throws WxErrorException, IOException {
HttpRequest request = HttpRequest.post(uri);
if (requestHttp.getRequestHttpProxy() != null) {
requestHttp.getRequestHttpClient().useProxy(requestHttp.getRequestHttpProxy());
}
request.withConnectionProvider(requestHttp.getRequestHttpClient());
request.form("media", file);
HttpResponse response = request.send();
response.charset(StandardCharsets.UTF_8.name());
String responseContent = response.bodyText();
WxError error = WxError.fromJson(responseContent, wxType);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
}
return WxMaUploadAuthMaterialResult.fromJson(responseContent);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/OkHttpVodSingleUploadRequestExecutor.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/OkHttpVodSingleUploadRequestExecutor.java | package cn.binarywang.wx.miniapp.executor;
import cn.binarywang.wx.miniapp.bean.vod.WxMaVodSingleFileUploadResult;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo;
import okhttp3.*;
import java.io.File;
import java.io.IOException;
/**
*
*/
public class OkHttpVodSingleUploadRequestExecutor extends VodSingleUploadRequestExecutor<OkHttpClient, OkHttpProxyInfo> {
public OkHttpVodSingleUploadRequestExecutor(RequestHttp<OkHttpClient, OkHttpProxyInfo> requestHttp, String mediaName, String mediaType, String coverType, File coverData, String sourceContext) {
super(requestHttp, mediaName, mediaType, coverType, coverData, sourceContext);
}
@Override
public WxMaVodSingleFileUploadResult execute(String uri, File file, WxType wxType) throws WxErrorException, IOException {
MultipartBody.Builder bodyBuilder = new MultipartBody.Builder()
.setType(MediaType.parse("multipart/form-data"))
.addFormDataPart("media_data",
file.getName(),
RequestBody.create(MediaType.parse("application/octet-stream"), file));
bodyBuilder.addFormDataPart("media_type", this.mediaType)
.addFormDataPart("media_name", this.mediaName);
if (coverType != null) {
bodyBuilder.addFormDataPart("cover_type", this.coverType);
}
if (coverData != null) {
bodyBuilder.addFormDataPart("cover_data",
coverData.getName(),
RequestBody.create(MediaType.parse("application/octet-stream"), coverData));
}
if (sourceContext != null) {
bodyBuilder.addFormDataPart("source_context", this.sourceContext);
}
Request request = new Request.Builder().url(uri).post(bodyBuilder.build()).build();
Response response = requestHttp.getRequestHttpClient().newCall(request).execute();
String responseContent = response.body().string();
WxError error = WxError.fromJson(responseContent, wxType);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
}
return WxMaVodSingleFileUploadResult.fromJson(responseContent);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/ApacheVodUploadPartRequestExecutor.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/ApacheVodUploadPartRequestExecutor.java | package cn.binarywang.wx.miniapp.executor;
import cn.binarywang.wx.miniapp.bean.vod.WxMaVodUploadPartResult;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler;
import org.apache.http.HttpHost;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import java.io.File;
import java.io.IOException;
/**
*
*/
public class ApacheVodUploadPartRequestExecutor extends VodUploadPartRequestExecutor<CloseableHttpClient, HttpHost> {
public ApacheVodUploadPartRequestExecutor(RequestHttp<CloseableHttpClient, HttpHost> requestHttp, String uploadId, Integer partNumber, Integer resourceType) {
super(requestHttp, uploadId, partNumber, resourceType);
}
@Override
public WxMaVodUploadPartResult execute(String uri, File file, WxType wxType) throws WxErrorException, IOException {
HttpPost httpPost = new HttpPost(uri);
if (requestHttp.getRequestHttpProxy() != null) {
RequestConfig config = RequestConfig.custom().setProxy(requestHttp.getRequestHttpProxy()).build();
httpPost.setConfig(config);
}
if (file != null) {
MultipartEntityBuilder entityBuilder = MultipartEntityBuilder
.create()
.setMode(HttpMultipartMode.RFC6532)
.addTextBody("upload_id", uploadId)
.addTextBody("part_number", String.valueOf(partNumber))
.addTextBody("resource_type", String.valueOf(resourceType))
.addBinaryBody("data", file);
httpPost.setEntity(entityBuilder.build());
}
String responseContent = requestHttp.getRequestHttpClient().execute(httpPost, Utf8ResponseHandler.INSTANCE);
WxError error = WxError.fromJson(responseContent, wxType);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
}
return WxMaVodUploadPartResult.fromJson(responseContent);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/HttpComponentsQrcodeFileRequestExecutor.java | weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/HttpComponentsQrcodeFileRequestExecutor.java | package cn.binarywang.wx.miniapp.executor;
import cn.binarywang.wx.miniapp.bean.AbstractWxMaQrcodeWrapper;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.fs.FileUtils;
import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.hc.InputStreamResponseHandler;
import me.chanjar.weixin.common.util.http.hc.Utf8ResponseHandler;
import org.apache.commons.lang3.StringUtils;
import org.apache.hc.client5.http.ClientProtocolException;
import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.io.entity.StringEntity;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Paths;
import java.util.UUID;
/**
* @author altusea
*/
public class HttpComponentsQrcodeFileRequestExecutor extends QrcodeRequestExecutor<CloseableHttpClient, HttpHost> {
private final String filePath;
public HttpComponentsQrcodeFileRequestExecutor(RequestHttp<CloseableHttpClient, HttpHost> requestHttp, String filePath) {
super(requestHttp);
this.filePath = filePath;
}
/**
* 执行http请求.
*
* @param uri uri
* @param qrcodeWrapper 数据
* @param wxType 微信模块类型
* @return 响应结果
* @throws WxErrorException 自定义异常
* @throws IOException io异常
*/
@Override
public File execute(String uri, AbstractWxMaQrcodeWrapper qrcodeWrapper, WxType wxType) throws WxErrorException, IOException {
HttpPost httpPost = new HttpPost(uri);
if (requestHttp.getRequestHttpProxy() != null) {
httpPost.setConfig(
RequestConfig.custom().setProxy(requestHttp.getRequestHttpProxy()).build()
);
}
httpPost.setEntity(new StringEntity(qrcodeWrapper.toJson(), ContentType.APPLICATION_JSON));
try (final CloseableHttpResponse response = requestHttp.getRequestHttpClient().execute(httpPost);
final InputStream inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response)) {
Header[] contentTypeHeader = response.getHeaders("Content-Type");
if (contentTypeHeader != null && contentTypeHeader.length > 0
&& ContentType.APPLICATION_JSON.getMimeType()
.equals(ContentType.parse(contentTypeHeader[0].getValue()).getMimeType())) {
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
throw new WxErrorException(WxError.fromJson(responseContent, wxType));
}
if (StringUtils.isBlank(filePath)) {
return FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), "jpg");
}
return FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), "jpg", Paths.get(filePath).toFile());
} catch (HttpException httpException) {
throw new ClientProtocolException(httpException.getMessage(), httpException);
}
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.