- 开发者申请
- 认证授权
- 订单抓取
- 订单状态更新
授权流程
- 官网申请开发者
- 创建应用APP(勾选响应的权限)
- 发布应用(得到clientid,client_secret )
- 通过授权码获取店铺授权token以及refreshtoken,并保存到数据
token刷新代码
/// <summary>
/// 获取获取有效token
/// </summary>
/// <param name="storeInfoDto"></param>
/// <returns></returns>
private async Task<string> GetAccessToken(WishStoreInfoDto storeInfoDto)
{
if (storeInfoDto.Oauthorization_date <= DateTime.UtcNow.AddMinutes(-1))
{
var tokenString = await _httpClient.GetAsync("https://merchant.wish.com/api/v3/oauth/refresh_token",
new Dictionary<string, string>() { { "Authorization", storeInfoDto.refresh_token } }
);
var newToken = JObject.Parse(tokenString);
storeInfoDto.Token = newToken.Value<string>("access_token");
storeInfoDto.Oauthorization_date = newToken.Value<DateTime>("expiry_time");
storeInfoDto.refresh_token = newToken.Value<string>("refresh_token"); //利用废弃字段存储token
await _storeInfoAppService.UpdateStoreAuthInfoAsync(storeInfoDto);
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine($"刷新token有效期至{storeInfoDto.Oauthorization_date}");
Console.ForegroundColor = ConsoleColor.White;
}
return storeInfoDto.Token;
}
订单抓取(直接上代码)
// 主要API merchant.wish.com/api/v3/orders
await _httpClient.GetAsync($"https://merchant.wish.com/api/v3/orders?limit=500&states={"APPROVED"}&released_at_min={lastDateTime}&sort_by=released_at&order_type=WISH_EXPRESS", new Dictionary<string, string>() { { "Authorization", await GetAccessToken(storeInfo) } });
接口内容解析成jarray数组,按官方文档解析即可,导入到erp或公司内部系统
发货通知及物流单号推送
return new WishSalesOrderDto()
{
Currency = (order["order_payment"] != null) ? order["general_payment_details"]["payment_total"].Value<string>("currency_code") : "USD",
Customer_info = order["order_payment"].ToJsonString(),
Customer_receiver = order["full_address"].IsNullOrEmpty() ? "{}" : order["full_address"].ToJsonString(),
Is_wholesale = true,
Items = order["product_information"].ToJsonString(),
San_code = order.Value<string>("id"),
Sb_id = order.Value<string>("id"),
Create_at = order.Value<DateTime>("released_at"),
Create_date = order.Value<DateTime>("released_at"),
Package_info = order.Value<string>("tracking_information"),
//发货号 需要保存 上传物流跟踪单号需要用到
//Supplier_account_fullname = order.Value<string>("posting_number"),
Supplier_sender_branch_fullname = "tvcmall-wish"
};