第一步 获取全部推广商品实体
需要使用类
ITopClient TOP客户端类
View Code 1 using Top.Api.Request; 2 3 namespace Top.Api 4 { 5 ///
6 /// TOP客户端。 7 /// 8 public interface ITopClient 9 {
10 ///
11 /// 执行TOP公开API请求。
12 ///
13 ///
领域对象
14 /// 具体的TOP API请求
15 ///
领域对象
16 T Execute
(ITopRequest request) where T : TopResponse;
17 18 ///
19 /// 执行TOP隐私API请求。
20 ///
21 /// 领域对象
22 /// 具体的TOP API请求
23 /// 用户会话码
24 /// 领域对象
25 T Execute(ITopRequest request, string session) where T : TopResponse;
26 }
27 }
DefaultTopClient 初始化连接(请求地址, Appkey, AppSecret);
View Code 1 using System; 2 using System.Collections; 3 using System.Collections.Generic; 4 using Top.Api.Parser; 5 using Top.Api.Request; 6 using Top.Api.Util; 7 8 namespace Top.Api 9 { 10 /// 11 /// 基于REST的TOP客户端。 12 /// 13 public class DefaultTopClient : ITopClient 14 { 15 public const string APP_KEY = "app_key"; 16 public const string FORMAT = "format"; 17 public const string METHOD = "method"; 18 public const string TIMESTAMP = "timestamp"; 19 public const string VERSION = "v"; 20 public const string SIGN = "sign"; 21 public const string PARTNER_ID = "partner_id"; 22 public const string SESSION = "session"; 23 public const string FORMAT_XML = "xml"; 24 25 private string serverUrl; 26 private string appKey; 27 private string appSecret; 28 private string format = FORMAT_XML; 29 30 private WebUtils webUtils; 31 32 #region DefaultTopClient Constructors 33 34 public DefaultTopClient(string serverUrl, string appKey, string appSecret) 35 { 36 this.appKey = appKey; 37 this.appSecret = appSecret; 38 this.serverUrl = serverUrl; 39 this.webUtils = new WebUtils(); 40 } 41 42 public DefaultTopClient(string serverUrl, string appKey, string appSecret, string format) 43 : this(serverUrl, appKey, appSecret) 44 { 45 this.format = format; 46 } 47 48 public void SetTimeout(int timeout) 49 { 50 webUtils.Timeout = timeout; 51 } 52 53 #endregion 54 55 #region ITopClient Members 56 57 public T Execute(ITopRequest request) where T : TopResponse 58 { 59 return Execute(request, null); 60 } 61 62 public T Execute(ITopRequest request, string session) where T : TopResponse 63 { 64 // 添加协议级请求参数 65 TopDictionary txtParams = new TopDictionary(request.GetParameters()); 66 txtParams.Add(METHOD, request.GetApiName()); 67 txtParams.Add(VERSION, "2.0"); 68 txtParams.Add(APP_KEY, appKey); 69 txtParams.Add(FORMAT, format); 70 txtParams.Add(PARTNER_ID, "top-sdk-net-20110317"); 71 txtParams.Add(TIMESTAMP, DateTime.Now); 72 txtParams.Add(SESSION, session); 73 74 // 添加签名参数 75 txtParams.Add(SIGN, TopUtils.SignTopRequest(txtParams, appSecret)); 76 77 // 是否需要上传文件 78 string body; 79 if (request is ITopUploadRequest) 80 { 81 ITopUploadRequest uRequest = (ITopUploadRequest)request; 82 IDictionary fileParams = TopUtils.CleanupDictionary(uRequest.GetFileParameters()); 83 body = webUtils.DoPost(this.serverUrl, txtParams, fileParams); 84 } 85 else 86 { 87 body = webUtils.DoPost(this.serverUrl, txtParams); 88 } 89 90 T rsp; 91 if (FORMAT_XML.Equals(format)) 92 { 93 ITopParser tp = new TopXmlParser(); 94 rsp = tp.Parse(body); 95 } 96 else 97 { 98 ITopParser tp = new TopJsonParser(); 99 rsp = tp.Parse(body);
100 }
101 102 return rsp;
103 }
104 105 #endregion
106 }
107 }
TaobaokeItemsGetResponse 信息返回
View Code 1 using System; 2 using System.Xml.Serialization; 3 using System.Collections.Generic; 4 using Top.Api.Domain; 5 6 namespace Top.Api.Response 7 { 8 /// 9 /// TaobaokeItemsGetResponse.
10 ///
11 public class TaobaokeItemsGetResponse : TopResponse
12 {
13 ///
14 /// 淘宝客商品对象列表.不返回taobaoke_cat_click_url和keyword_click_url两个字段。
15 ///
16 [XmlArray("taobaoke_items")]
17 [XmlArrayItem("taobaoke_item")]
18 public List TaobaokeItems { get; set; }
19 20 ///
21 /// 搜索到符合条件的结果总数
22 ///
23 [XmlElement("total_results")]
24 public long TotalResults { get; set; }
25 }
26 }
剩下的实体绑定不需要我说了吧 www.qtcrm.com 首页信息显示就是通过这个获取到的 类型与
数量等信息在请求类中条件设置
TaobaokeItemsGetRequest 在请求类中设置相应条件信息。
View Code 1 using System; 2 using System.Collections.Generic; 3 using Top.Api.Response; 4 5 namespace Top.Api.Request 6 { 7 /// 8 /// TOP API: taobao.taobaoke.items.get 9 /// 10 public class TaobaokeItemsGetRequest : ITopRequest 11 { 12 /// 13 /// 商品所在地 14 /// 15 public string Area { get; set; } 16 17 /// 18 /// 是否自动发货 19 /// 20 public string AutoSend { get; set; } 21 22 /// 23 /// 是否支持抵价券,设置为true表示该商品支持抵价券,设置为false或不设置表示不判断这个属性 24 /// 25 public string CashCoupon { get; set; } 26 27 /// 28 /// 是否支持货到付款,设置为true表示该商品是支持货到付款,设置为false或不设置表示不判断这个属性 29 /// 30 public string CashOndelivery { get; set; } 31 32 /// 33 /// 商品所属分类id 34 /// 35 public Nullable Cid { get; set; } 36 37 /// 38 /// 最高累计推广佣金选项 39 /// 40 public string EndCommissionNum { get; set; } 41 42 /// 43 /// 最高佣金比率选项,如:2345表示23.45%。注:要起始佣金比率和最高佣金比率一起设置才有效。 44 /// 45 public string EndCommissionRate { get; set; } 46 47 /// 48 /// 可选值和start_credit一样.start_credit的值一定要小于或等于end_credit的值。注:end_credit与start_credit一起使用才生效 49 /// 50 public string EndCredit { get; set; } 51 52 /// 53 /// 最高价格 54 /// 55 public string EndPrice { get; set; } 56 57 /// 58 /// 累计推广量范围结束 59 /// 60 public string EndTotalnum { get; set; } 61 62 /// 63 /// 需返回的字段列表.可选值:num_iid,title,nick,pic_url,price,click_url,commission,commission_rate,commission_num,commission_volume,shop_click_url,seller_credit_score,item_location,volume ;字段之间用","分隔 64 /// 65 public string Fields { get; set; } 66 67 /// 68 /// 是否查询消保卖家 69 /// 70 public string Guarantee { get; set; } 71 72 /// 73 /// 标识一个应用是否来在无线或者手机应用,如果是true则会使用其他规则加密点击串.如果不穿值,则默认是false. 74 /// 75 public Nullable IsMobile { get; set; } 76 77 /// 78 /// 商品标题中包含的关键字. 注意:查询时keyword,cid至少选择其中一个参数 79 /// 80 public string Keyword { get; set; } 81 82 /// 83 /// 是否商城的商品,设置为true表示该商品是属于淘宝商城的商品,设置为false或不设置表示不判断这个属性 84 /// 85 public string MallItem { get; set; } 86 87 /// 88 /// 淘宝用户昵称,注:指的是淘宝的会员登录名.如果昵称错误,那么客户就收不到佣金.每个淘宝昵称都对应于一个pid,在这里输入要结算佣金的淘宝昵称,当推广的商品成功后,佣金会打入此输入的淘宝昵称的账户。具体的信息可以登入阿里妈妈的网站查看. 注意nick和pid至少需要传递一个,如果2个都传了,将以pid为准 89 /// 90 public string Nick { get; set; } 91 92 /// 93 /// 是否30天维修,设置为true表示该商品是支持30天维修,设置为false或不设置表示不判断这个属性 94 /// 95 public string _disibledevent=>get; set; } 96 97 /// 98 /// 自定义输入串.格式:英文和数字组成;长度不能大于12个字符,区分不同的推广渠道,如:bbs,表示bbs为推广渠道;blog,表示blog为推广渠道. 99 ///
100 public string OuterCode { get; set; }
101 102 ///
103 /// 是否海外商品,设置为true表示该商品是属于海外商品,默认为false
104 ///
105 public string OverseasItem { get; set; }
106 107 ///
108 /// 结果页数.1~99
109 ///
110 public Nullable PageNo { get; set; }
111 112 ///
113 /// 每页返回结果数.最大每页40
114 ///
115 public Nullable PageSize { get; set; }
116 117 ///
118 /// 用户的pid,必须是mm_xxxx_0_0这种格式中间的"xxxx". 注意nick和pid至少需要传递一个,如果2个都传了,将以pid为准,且pid的最大长度是20
119 ///
120 public string Pid { get; set; }
121 122 ///
123 /// 是否如实描述(即:先行赔付)商品,设置为true表示该商品是如实描述的商品,设置为false或不设置表示不判断这个属性
124 ///
125 public string RealDescribe { get; set; }
126 127 ///
128 /// 是否支持7天退换,设置为true表示该商品支持7天退换,设置为false或不设置表示不判断这个属性
129 ///
130 public string SevendaysReturn { get; set; }
131 132 ///
133 /// 默认排序:default price_desc(价格从高到低) price_asc(价格从低到高) credit_desc(信用等级从高到低) commissionRate_desc(佣金比率从高到底) commissionRate_asc(佣金比率从低到高) commissionNum_desc(成交量成高到低) commissionNum_asc(成交量从低到高) commissionVolume_desc(总支出佣金从高到底) commissionVolume_asc(总支出佣金从低到高) delistTime_desc(商品下架时间从高到底) delistTime_asc(商品下架时间从低到高)
134 ///
135 public string Sort { get; set; }
136 137 ///
138 /// 起始累计推广量佣金.注:返回的数据是30天内累计推广量,具该字段要与最高累计推广量一起使用才生效
139 ///
140 public string StartCommissionNum { get; set; }
141 142 ///
143 /// 起始佣金比率选项,如:1234表示12.34%
144 ///
145 public string StartCommissionRate { get; set; }
146 147 ///
148 /// 卖家信用: 1heart(一心) 2heart (两心) 3heart(三心) 4heart(四心) 5heart(五心) 1diamond(一钻) 2diamond(两钻) 3diamond(三钻) 4diamond(四钻) 5diamond(五钻) 1crown(一冠) 2crown(两冠) 3crown(三冠) 4crown(四冠) 5crown(五冠) 1goldencrown(一黄冠) 2goldencrown(二黄冠) 3goldencrown(三黄冠) 4goldencrown(四黄冠) 5goldencrown(五黄冠)
149 ///
150 public string StartCredit { get; set; }
151 152 ///
153 /// 起始价格.传入价格参数时,需注意起始价格和最高价格必须一起传入,并且 start_price <= end_price
154 ///
155 public string StartPrice { get; set; }
156 157 ///
158 /// 累计推广量范围开始
159 ///
160 public string StartTotalnum { get; set; }
161 162 ///
163 /// 是否支持VIP卡,设置为true表示该商品支持VIP卡,设置为false或不设置表示不判断这个属性
164 ///
165 public string VipCard { get; set; }
166 167 #region ITopRequest Members
168 169 public string GetApiName()
170 {
171 return "taobao.taobaoke.items.get";
172 }
173 174 public IDictionary GetParameters()
175 {
176 TopDictionary parameters = new TopDictionary();
177 parameters.Add("area", this.Area);
178 parameters.Add("auto_send", this.AutoSend);
179 parameters.Add("cash_coupon", this.CashCoupon);
180 parameters.Add("cash_ondelivery", this.CashOndelivery);
181 parameters.Add("cid", this.Cid);
182 parameters.Add("end_commissionNum", this.EndCommissionNum);
183 parameters.Add("end_commissionRate", this.EndCommissionRate);
184 parameters.Add("end_credit", this.EndCredit);
185 parameters.Add("end_price", this.EndPrice);
186 parameters.Add("end_totalnum", this.EndTotalnum);
187 parameters.Add("fields", this.Fields);
188 parameters.Add("guarantee", this.Guarantee);
189 parameters.Add("is_mobile", this.IsMobile);
190 parameters.Add("keyword", this.Keyword);
191 parameters.Add("mall_item", this.MallItem);
192 parameters.Add("nick", this.Nick);
193 parameters.Add("onemonth_repair", this.OnemonthRepair);
194 parameters.Add("outer_code", this.OuterCode);
195 parameters.Add("overseas_item", this.OverseasItem);
196 parameters.Add("page_no", this.PageNo);
197 parameters.Add("page_size", this.PageSize);
198 parameters.Add("pid", this.Pid);
199 parameters.Add("real_describe", this.RealDescribe);
200 parameters.Add("sevendays_return", this.SevendaysReturn);
201 parameters.Add("sort", this.Sort);
202 parameters.Add("start_commissionNum", this.StartCommissionNum);
203 parameters.Add("start_commissionRate", this.StartCommissionRate);
204 parameters.Add("start_credit", this.StartCredit);
205 parameters.Add("start_price", this.StartPrice);
206 parameters.Add("start_totalnum", this.StartTotalnum);
207 parameters.Add("vip_card", this.VipCard);
208 return parameters;
209 }
210 211 #endregion
212 }
213 }
淘宝客起初有调用次数限制 请注意优化缓存 否则将无法显示数据信息。并且网站打开异常缓慢,建议单独写个控制类方法 方便修改于后续的 缓存信息定义。好了 今天很晚了
这几天公司比较忙 没有更新 如果大家需要了解什么 以后陆续更新
如果对www.qtcrm.com上面的那些技术应用有急需了解的请 留言 我将在下篇文章中详细解释。 写的不好希望大家海涵。
希望可以帮到 愿意走淘宝客之路的朋友。
/// /// taobao.taobaoke.items.get 查询淘宝客推广商品 /// /// 请求实体参数
/// 返回商品实体数组 public static TaobaokeItem[] GetItemArray(TaobaokeItemsGetRequest req) { ITopClient client = new DefaultTopClient(Config.ServerURL, Config.Appkey, Config.AppSecret); req.Pid = Config.Pid;///淘宝客PID 可以到阿里妈妈查询 TaobaokeItemsGetResponse response = client.Execute(req); if (response.IsError) { string err = response.ErrMsg; string ierr = response.ErrCode; ErrorLog.Save("TaobaokeAPI", ierr, err, All.GetErrorCN(int.Parse(ierr))); } return response.TotalResults > 0 ? response.TaobaokeItems.ToArray() : null; }
Tags:
延伸阅读
最新评论