查询商品列表及本地化价格显示
业务场景
用于商品界面的价格需要在不同地区对应显示该地区的货币和金额。
注意事项
- 为提高用户体验, 此接口应尽早调用(建议在 SDK 初始化成功后即调用), 以便让用户在点击商品时就能看到正确的本地化价格
流程图
无
接口介绍
/**
* 查询商品列表及本地化价格
*
* @param productIdList 商品Id列表
*/
- (void)getProductList:(NSArray *)productIdList;
调用示例
// 监听回调通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onQuerySuccess:) name:NOTIFICATION_GET_PRODUCT_LIST_INFO_SUCCESS object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onQueryFailed:) name:NOTIFICATION_GET_PRODUCT_LIST_INFO_FAILED object:nil];
// 调用查询商品列表接口
NSArray *productIdList = @[@"productid_1",@"productid_2"];
[SDKManager.getInstance getProductList:productIdList];
// 查询列表回调
- (void)onQuerySuccess:(NSNotification *)notif
{
NSArray *productInfo_List = notif.userInfo[KEY_PRODUCTLIST_DATA];
if (productInfo_List)
{
NSMutableString *productListStr = @"\n".mutableCopy;
for (NSInteger i = 0; i < productInfo_List.count; i++)
{
ProductInfo *productInfo = (ProductInfo *)[productInfo_List objectAtIndex:i];
[productListStr appendString:[NSString stringWithFormat:@"Price : %@, ", productInfo.price]];
[productListStr appendString:[NSString stringWithFormat:@"ProductId : %@, ",productInfo.productId]];
[productListStr appendString:[NSString stringWithFormat:@"displayPrice : %@, ",productInfo.displayPrice]];
[productListStr appendString:[NSString stringWithFormat:@"localPrice : %@, ",productInfo.localPrice]];
[productListStr appendString:[NSString stringWithFormat:@"currency : %@, ",productInfo.currency]];
[productListStr appendString:[NSString stringWithFormat:@"localCurrency : %@\n\n",productInfo.localCurrency]];
}
NSLog(@"获取商品列表成功: %@",productListStr);
}
else
{
[self onQueryFailed:nil];
}
}
- (void)onQueryFailed:(NSNotification *)notif
{
NSDictionary *errorInfo = notif.userInfo;
NSString *errorMsg = [errorInfo objectForKey:KEY_ERROR_MSG];
NSInteger errorCode = [[errorInfo objectForKey:KEY_ERROR_CODE] integerValue];
[self textViewLog:[NSString stringWithFormat:@"获取商品列表失败: %@(%ld)", errorMsg, errorCode]];
}
参数说明
【入参】
参数名称 | 类型 | 说明 |
---|---|---|
productIdList | NSArray | 商品列表 |
出参
参数名称 | 类型 | 说明 |
---|---|---|
productId | NSString | 游戏方商品 Id |
price | NSString | 默认价格,与 SDK 交互时使用此价格,默认固定为美元,如:0.99 |
currency | NSString | price 对应的货币代号, 默认固定为 USD |
displayPrice | NSString | 显示价格,包含货币符号,如:NZD$1.42,所显示的价格为用户本地的价格和货币,与用户在 Google 支付界面实际支付金额一致,兑率由 Google 控制 |
localPrice | NSString | 用户本地化价格,与 displayPrice 一致但不包含货币前缀,如:1.42 |
localCurrency | NSString | 用户本地化货币代号,与 localPrice 对应,如:NZD |
goodsDescription | NSString | 商品描述 |
错误码
无
FAQ
Q:为什么要查询商品列表及本地化价格显示?
A:游戏方需要展示商品列表及本地化价格显示,需要通过接口查询商品列表及本地化价格显示数据。
Q:商品列表及本地化价格显示数据有什么用?
A:商品列表及本地化价格显示数据主要用于展示商品列表及本地化价格显示,包括商品 Id、默认价格、货币、显示价格、本地化价格、本地化货币、商品描述等信息。