Skip to content

Commit

Permalink
Merge pull request #3078 from mc7246/master
Browse files Browse the repository at this point in the history
添加 查询购买资源包的用量情况
  • Loading branch information
JeffreySu authored Oct 8, 2024
2 parents 10b79e7 + 19018df commit b571822
Show file tree
Hide file tree
Showing 4 changed files with 275 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using Senparc.NeuChar;
using Senparc.Weixin.CommonAPIs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Senparc.Weixin.WxOpen.AdvancedAPIs.Charge
{
[NcApiBind(NeuChar.PlatformType.WeChat_MiniProgram, true)]
public class ChargeApi
{
#region 同步方法
/// <summary>
/// 查询购买资源包的用量情况
/// </summary>
/// <param name="accessTokenOrAppId"></param>
/// <param name="spuId">商品SPU ID</param>
/// <param name="offset">分页偏移量,从0开始</param>
/// <param name="limit"每页个数,最大20></param>
/// <param name="timeOut"></param>
/// <returns></returns>
public static UsageResultJson Usage(string accessTokenOrAppId, string spuId, int offset, int limit, int timeOut = Config.TIME_OUT)
{
return WxOpenApiHandlerWapper.TryCommonApi(accessToken =>
{
var urlFormat = Config.ApiMpHost + "/wxa/charge/usage/get?access_token={0}&spuId=" + spuId + "&offset=" + offset+ "&limit=" + limit;
return CommonJsonSend.Send<UsageResultJson>(accessToken, urlFormat, null, CommonJsonSendType.GET, timeOut: timeOut);

}, accessTokenOrAppId);
}

/// <summary>
/// 获取小程序某个付费能力的最近用量数据
/// </summary>
/// <param name="accessTokenOrAppId"></param>
/// <param name="spuId">商品SPU ID</param>
/// <param name="timeOut"></param>
/// <returns></returns>
public static GetRecentAverageResultJson GetRecentAverage(string accessTokenOrAppId, string spuId, int timeOut = Config.TIME_OUT)
{
return WxOpenApiHandlerWapper.TryCommonApi(accessToken =>
{
var urlFormat = Config.ApiMpHost + "/wxa/charge/usage/get_recent_average?access_token={0}&spuId=" + spuId;
return CommonJsonSend.Send<GetRecentAverageResultJson>(accessToken, urlFormat, null, CommonJsonSendType.GET, timeOut: timeOut);

}, accessTokenOrAppId);
}
#endregion

#region 异步方法
/// <summary>
/// 【异步方法】查询购买资源包的用量情况
/// </summary>
/// <param name="accessTokenOrAppId"></param>
/// <param name="spuId">商品SPU ID</param>
/// <param name="offset">分页偏移量,从0开始</param>
/// <param name="limit"每页个数,最大20></param>
/// <param name="timeOut"></param>
/// <returns></returns>
public static async Task<UsageResultJson> UsageAsync(string accessTokenOrAppId, string spuId, int offset, int limit, int timeOut = Config.TIME_OUT)
{
return await WxOpenApiHandlerWapper.TryCommonApiAsync(async accessToken =>
{
var urlFormat = Config.ApiMpHost + "/wxa/charge/usage/get?access_token={0}&spuId=" + spuId + "&offset=" + offset + "&limit=" + limit;
return await CommonJsonSend.SendAsync<UsageResultJson>(accessToken, urlFormat, null, CommonJsonSendType.GET, timeOut: timeOut).ConfigureAwait(false);

}, accessTokenOrAppId).ConfigureAwait(false);
}

/// <summary>
/// 【异步方法】获取小程序某个付费能力的最近用量数据
/// </summary>
/// <param name="accessTokenOrAppId"></param>
/// <param name="spuId">商品SPU ID</param>
/// <param name="timeOut"></param>
/// <returns></returns>
public static async Task<GetRecentAverageResultJson> GetRecentAverageAsync(string accessTokenOrAppId, string spuId, int timeOut = Config.TIME_OUT)
{
return await WxOpenApiHandlerWapper.TryCommonApiAsync(async accessToken =>
{
var urlFormat = Config.ApiMpHost + "/wxa/charge/usage/get_recent_average?access_token={0}&spuId=" + spuId;
return await CommonJsonSend.SendAsync<GetRecentAverageResultJson>(accessToken, urlFormat, null, CommonJsonSendType.GET, timeOut: timeOut).ConfigureAwait(false);

}, accessTokenOrAppId).ConfigureAwait(false);
}
#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#region Apache License Version 2.0
/*----------------------------------------------------------------
Copyright 2024 Jeffrey Su & Suzhou Senparc Network Technology Co.,Ltd.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
either express or implied. See the License for the specific language governing permissions
and limitations under the License.
Detail: https://github.com/JeffreySu/WeiXinMPSDK/blob/master/license.md
----------------------------------------------------------------*/
#endregion Apache License Version 2.0

/*----------------------------------------------------------------
Copyright (C) 2024 Senparc
文件名:GetRecentAverageResultJson.cs
文件功能描述:小程序 获取小程序某个付费能力的最近用量数据 返回结果
创建标识:mc7246 - 20240831
----------------------------------------------------------------*/

using Senparc.Weixin.Entities;

namespace Senparc.Weixin.WxOpen.AdvancedAPIs.Charge
{
/// <summary>
/// 小程序 获取小程序某个付费能力的最近用量数据 返回结果
/// </summary>
public class GetRecentAverageResultJson: WxJsonResult
{
/// <summary>
/// 最近月平均用量,经模糊化处理,非精确值
/// 当averageData返回值为50时,语义为小程序最近平均用量小于等于50次/月,并不是特指精确等于每月50次。
/// </summary>
public int averageData { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#region Apache License Version 2.0
/*----------------------------------------------------------------
Copyright 2024 Jeffrey Su & Suzhou Senparc Network Technology Co.,Ltd.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
either express or implied. See the License for the specific language governing permissions
and limitations under the License.
Detail: https://github.com/JeffreySu/WeiXinMPSDK/blob/master/license.md
----------------------------------------------------------------*/
#endregion Apache License Version 2.0

/*----------------------------------------------------------------
Copyright (C) 2024 Senparc
文件名:UsageResultJson.cs
文件功能描述:小程序 查询购买资源包的用量情况 返回结果
创建标识:mc7246 - 20240831
----------------------------------------------------------------*/

using Senparc.Weixin.Entities;
using System.Collections.Generic;

namespace Senparc.Weixin.WxOpen.AdvancedAPIs.Charge
{
/// <summary>
/// 小程序-查询购买资源包的用量情况 返回结果
/// </summary>
public class UsageResultJson : WxJsonResult
{
/// <summary>
/// 资源可用总量(64位数字),用于资源包类商品
/// </summary>
public string all { get; set; }

/// <summary>
/// 资源总量(64位数字),用于资源包类商品
/// </summary>
public string effectiveAll { get; set; }

/// <summary>
/// 累计用量(64位数字),用于资源包类商品
/// </summary>
public string effectiveUse { get; set; }

/// <summary>
/// 订阅开始时间戳(单位:秒),用于订阅类商品
/// </summary>
public long startServiceTime { get; set; }

/// <summary>
/// 订阅结束时间戳(单位:秒),用于订阅类商品
/// </summary>
public long endServiceTime { get; set; }

/// <summary>
/// 用量详情列表总数
/// </summary>
public int total { get; set; }

/// <summary>
/// 用量详情列表
/// </summary>
public List<UsageResultJson_DetailList> detailList { get; set; }
}

public class UsageResultJson_DetailList
{
/// <summary>
/// 资源包ID
/// </summary>
public string pkgId { get; set; }

/// <summary>
/// 资源包状态,1生效中,2未生效,3已失效
/// </summary>
public int status { get; set; }

/// <summary>
/// 额度有效期开始时间戳(单位:秒)
/// </summary>
public long startTime { get; set; }

/// <summary>
/// 额度有效期至结束时间戳(单位:秒)
/// </summary>
public long endTime { get; set; }

/// <summary>
/// 使用额度(64位数字)
/// </summary>
public string used { get; set; }

/// <summary>
/// 额度容量(64位数字)
/// </summary>
public string all { get; set; }

/// <summary>
/// 额度来源的商品SPU ID(64位数字)
/// </summary>
public string spuId { get; set; }

/// <summary>
/// 额度来源的商品SKU ID(64位数字)
/// </summary>
public string skuId { get; set; }

/// <summary>
/// 额度来源,1体验额度,2付费购买,3服务商分配,4其他,5其他
/// </summary>
public int source { get; set; }

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ public override IRequestMessageBase GetRequestEntityMappingResult(RequestMsgType
case "WX_VERIFY_DISPATCH": //微信认证派单事件
requestMessage = new RequestMessageEvent_WxVerifyDispatch();
break;
case "USER_INFO_MODIFIED": //用户资料变更
requestMessage = new RequestMessageEvent_UserInfoModified();
break;
case "USER_AUTHORIZATION_REVOKE": //用户撤回
requestMessage = new RequestMessageEvent_UserAuthorizationRevoke();
break;
case "USER_AUTHORIZATION_CANCELLATION": //用户完成注销
requestMessage = new RequestMessageEvent_UserAuthorizationCancellation();
break;
case "CHARGE_SERVICE_QUOTA_NOTIFY": //付费管理订单用量告警事件
requestMessage = new RequestMessageEvent_ChargeServiceQuotaNotify();
break;
default://其他意外类型(也可以选择抛出异常)
requestMessage = new RequestMessageEventBase();
break;
Expand Down

0 comments on commit b571822

Please sign in to comment.