多平台统一管理软件接口,如何实现多平台统一管理软件接口
300
2022-06-07
起始页面为Login.aspx,固定调试端口为49441。需要配合自己淘宝开放平台的应用的回调页面URL来调整。
ashx代码:(说明:代码中ITopClient为淘宝接口TopSdk.dll中的类,此例子使用的ItemsOnsaleGetRequest是用于获取销售中的商品,response.Body是获取到的数据信息)
复制代码代码如下:
public class OnsaleGet : IHttpHandler {
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; ITopClient client = new DefaultTopClient(Config.ServerURL, Config.Appkey, Config.Secret);
ItemsOnsaleGetRequest req = new ItemsOnsaleGetRequest(); req.Fields = "approve_status,num_iid,title,nick,type,cid,pic_url,num,props,valid_thru,list_time,price,has_discount,has_invoice,has_warranty,has_showcase,modified,delist_time,postage_id,seller_cids,outer_id"; ItemsOnsaleGetResponse response = client.Execute(req, Config.Top_session);
if (response.IsError) { context.Response.Write("[错误:查询函数执行失败]"); } else { context.Response.Write(response.Body); }
}
public bool IsReusable { get { return false; } } }
前端SL获取数据信息的方法
复制代码代码如下:
void GetList() { string absolutePath = HtmlPage.Document.DocumentUri.AbsoluteUri; string address = absolutePath.Substring(0, absolutePath.LastIndexOf('/')) + "/TaoBaoHandler/OnsaleGet.ashx";
Uri uri = new Uri(address);
WebClient client = new WebClient(); client.DownloadStringCompleted += (sender, e) => { if (e.Error == null) { System.Xml.Linq.XElement.Parse(e.Result);//字符串转为xml ItemsOnsaleGetResponse list = SerializeHelper.DeserializeFromString
SerializeHelper序列化部分是自定义的一个类
复制代码代码如下:
public class SerializeHelper { private SerializeHelper() { }
#region Serialize
///
XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); ns.Add("", ""); XmlWriterSettings writerSettings = new XmlWriterSettings(); writerSettings.OmitXmlDeclaration = true; StringWriter stringWriter = new StringWriter(); using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter, writerSettings)) { serializer.Serialize(xmlWriter, data, ns); } string xmlText = stringWriter.ToString();
return xmlText; } catch (InvalidOperationException ex) { if (ex.Message != "") { } }
return string.Empty; }
public static string SerializeList
XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); ns.Add("", ""); XmlWriterSettings writerSettings = new XmlWriterSettings(); writerSettings.OmitXmlDeclaration = true; StringWriter stringWriter = new StringWriter(); using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter, writerSettings)) { serializer.Serialize(xmlWriter, list, ns); } string xmlText = stringWriter.ToString();
return xmlText; } catch { }
return string.Empty; }
#endregion
#region Deserializer
///
return default(T); }
public static List
List
return list; } catch (InvalidOperationException ex) { if (ex.InnerException.Message != "") { } }
return null; }
#endregion }
web.config中的配置配置沙箱环境和正式环境的选择,以及AppKey和AppSecret
复制代码代码如下:
另外,web中的那些Client.cs和Config.cs则是从淘宝示例Demo中来的。
最终数据的获取如下:
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~