问下使用API接口怎么用.net写上传组件。 .netapi 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 using System;using System.Data;using System.Configuration;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;using System.Net;using System.IO;using System.Collections;using System.Globalization;using System.Text;using System.Text.RegularExpressions;/// <summary>///OpenApi 的摘要说明///56api接口/// </summary>public class donet_sdk{ public donet_sdk() { } private static String appkeyOne; private static String secretOne; #region 获取请求 /// <summary> /// 获取请求 /// </summary> /// <param name="apiurl">请求的接口</param> /// <param name="meth">请求方式</param> /// <param name="param">非系统参数</param> /// <param name="charset">编码</param> /// <param name="appkey">appkey</param> /// <param name="secret">secret</param> /// <returns></returns> public static String GetOpen56APi(String apiurl, String meth, String param, String charset, String appkey, String secret) { String str = "", PageCode = "", sign = ""; appkeyOne = appkey; secretOne = secret; Hashtable ht = new Hashtable(); String[] tag = { "&" }; String[] ss = param.Split(tag, StringSplitOptions.RemoveEmptyEntries); if (ss != null && ss.Length > 0) { for (int i = 0; i < ss.Length; i++) { String subPageCode = ss[i].ToString(); String[] tagg = { "=" }; String[] ss2 = subPageCode.Split(tagg, StringSplitOptions.RemoveEmptyEntries); if (ss2 != null && ss2.Length > 0) { String key = ss2[0].ToString(); String value = ss2[1].ToString(); if (key != "" && value != "") { ht.Add(key, value); } } } sign = signRequest(ht); str = apiurl + "?" + sign; try { PageCode = unicode_js_1(GetPageCode(str, charset, meth)).Replace("\\", ""); } catch (Exception ex) { PageCode = ex.ToString(); } } return PageCode; } #endregion #region 获取请求,默认测试帐号 /// <summary> /// 获取请求,默认测试帐号 /// </summary> /// <param name="apiurl">请求的接口</param> /// <param name="meth">请求方式</param> /// <param name="param">非系统参数</param> /// <param name="charset">编码</param> /// <returns></returns> public static String GetOpen56APiTest(String apiurl, String meth, String param,String charset) { String str = "", PageCode = "", sign=""; appkeyOne = "1000000010"; secretOne = "0e4f13954bc537ec"; Hashtable ht = new Hashtable(); String[] tag={"&"}; String[] ss = param.Split(tag, StringSplitOptions.RemoveEmptyEntries); if(ss!=null&&ss.Length>0) { for (int i = 0; i < ss.Length;i++ ) { String subPageCode = ss[i].ToString(); String [] tagg = {"="}; String[] ss2 = subPageCode.Split(tagg, StringSplitOptions.RemoveEmptyEntries); if(ss2!=null&&ss2.Length>0) { String key = ss2[0].ToString(); String value = ss2[1].ToString(); if(key!=""&&value!="") { ht.Add(key, value); } } } sign = signRequest(ht); str = apiurl + "?" + sign; try { PageCode = unicode_js_1(GetPageCode(str, charset, meth)).Replace("\\", ""); } catch (Exception ex) { PageCode = ex.ToString(); } } return PageCode; } /// <summary> /// unicode转中文(符合js规则的) /// </summary> /// <returns></returns> private static string unicode_js_1(string str) { string outStr = ""; Regex reg = new Regex(@"(?i)\\u([0-9a-f]{4})"); outStr = reg.Replace(str, delegate(Match m1) { return ((char)Convert.ToInt32(m1.Groups[1].Value, 16)).ToString(); }); return outStr; } #endregion #region Md5值加密 /// <summary> /// md5Run16 用md5 16位 加密输入字符串 /// </summary> /// <param name="strInput">输入字符串 </param> /// param name="num">md5指示位(16 or 32) </param> /// <returns>默认返回用md5 16位 加密后的字符串</returns> private static String md5Run(String strInput, int num) { if (strInput != null && strInput != "") { string hashedPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(strInput, "MD5");//md5 32位 if (num == 32) { return hashedPassword.ToLower(); } else { string MD5pwd32 = hashedPassword.Substring(8, 16).ToLower();//MD5 32位 } } return ""; } private static String signRequest(System.Collections.Hashtable hm) { String appkey = appkeyOne; String secret = secretOne; String req = md5Run(mapToString(hm), 32); //第一轮次计算 MD5加密 String sdate2 = System.DateTime.Now.ToString("yyyy-M-d HH:mm:ss"); String sdate1 = "1970-01-01 00:00:00"; System.TimeSpan timespan = Convert.ToDateTime(sdate2) - Convert.ToDateTime(sdate1); Int64 ts = Convert.ToInt64(timespan.TotalSeconds); hm.Add("sign", md5Run(req + "#" + appkey + "#" + secret + "#" + ts, 32)); //第二轮次计算 MD5加密 hm.Add("appkey", appkey); hm.Add("ts", ts); return mapToString(hm); } #endregion #region 将 map 中的参数及对应值转换为字符串 private static String mapToString(System.Collections.Hashtable hm) { int count = hm.Keys.Count; Object[] array = new Object[count]; hm.Keys.CopyTo(array, 0); System.Array.Sort(array); String str = ""; for (int i = 0; i < array.Count();i++ ) { String key = array[i].ToString(); if (i !=(array.Count()-1)) { str += key + "=" + hm[key] + "&"; } else { str += key + "=" + hm[key]; } } return str; } #endregion #region 获取源码 //获取指定页面的源代码 private static String GetPageCode(String PageURL, String Charset) { //存放目标网页的html String strHtml = ""; try { // Uri myUri = new Uri(PageURL); //连接到目标网页 WebRequest wreq = WebRequest.Create(PageURL); wreq.Method = "GET"; HttpWebResponse wresp = (HttpWebResponse)wreq.GetResponse(); //采用流读取,并确定编码方式 Stream s = wresp.GetResponseStream(); StreamReader objReader = new StreamReader(s, System.Text.Encoding.GetEncoding(Charset)); string strLine = ""; //读取 while (strLine != null) { strLine = objReader.ReadLine(); if (strLine != null) { strHtml += strLine.Trim(); } } return strHtml; } catch (Exception ei) //遇到错误,打印错误 { return strHtml = ei.ToString(); } } //获取指定页面的源代码 private static String GetPageCode(String PageURL, String Charset, String meth) { //存放目标网页的html String strHtml = ""; try { // Uri myUri = new Uri(PageURL); //连接到目标网页 WebRequest wreq = WebRequest.Create(PageURL); if (meth == "" || meth == null) { meth = "get"; } wreq.Method = meth; HttpWebResponse wresp = (HttpWebResponse)wreq.GetResponse(); //采用流读取,并确定编码方式 Stream s = wresp.GetResponseStream(); StreamReader objReader = new StreamReader(s, System.Text.Encoding.GetEncoding(Charset)); string strLine = ""; //读取 while (strLine != null) { strLine = objReader.ReadLine(); if (strLine != null) { strHtml += strLine.Trim(); } } return strHtml; } catch (Exception ei) //遇到错误,打印错误 { return strHtml = ei.ToString(); } } #endregion} 二楼是demo的代码,我该怎么去改 或者自己写。 Jquery Ztree插件的方法 不知哪里错. ASPxGridView控件的一个问题,上一页下一页不管用。 sqlserver order by排序问题 查找,。如果没有则提示 急!!!关于Excel如何导入GridView中遇到的问题 如何隐藏.aspx或.html扩展名? 超长曲线图形怎么做 我现在有一个购物网站用asp做的,想把购物车换成.net开发 求datalist分页方法. location 的 path 问题 asp向js传递参数问题 ckeditor_net 后台生成的问题~
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net;
using System.IO;
using System.Collections;
using System.Globalization;
using System.Text;
using System.Text.RegularExpressions;/// <summary>
///OpenApi 的摘要说明
///56api接口
/// </summary>
public class donet_sdk
{
public donet_sdk()
{
}
private static String appkeyOne;
private static String secretOne; #region 获取请求
/// <summary>
/// 获取请求
/// </summary>
/// <param name="apiurl">请求的接口</param>
/// <param name="meth">请求方式</param>
/// <param name="param">非系统参数</param>
/// <param name="charset">编码</param>
/// <param name="appkey">appkey</param>
/// <param name="secret">secret</param>
/// <returns></returns>
public static String GetOpen56APi(String apiurl, String meth, String param, String charset, String appkey, String secret)
{
String str = "", PageCode = "", sign = ""; appkeyOne = appkey; secretOne = secret; Hashtable ht = new Hashtable(); String[] tag = { "&" }; String[] ss = param.Split(tag, StringSplitOptions.RemoveEmptyEntries); if (ss != null && ss.Length > 0)
{
for (int i = 0; i < ss.Length; i++)
{
String subPageCode = ss[i].ToString(); String[] tagg = { "=" }; String[] ss2 = subPageCode.Split(tagg, StringSplitOptions.RemoveEmptyEntries); if (ss2 != null && ss2.Length > 0)
{
String key = ss2[0].ToString(); String value = ss2[1].ToString(); if (key != "" && value != "")
{
ht.Add(key, value);
}
}
} sign = signRequest(ht); str = apiurl + "?" + sign; try
{
PageCode = unicode_js_1(GetPageCode(str, charset, meth)).Replace("\\", ""); }
catch (Exception ex)
{
PageCode = ex.ToString();
}
} return PageCode;
} #endregion #region 获取请求,默认测试帐号
/// <summary>
/// 获取请求,默认测试帐号
/// </summary>
/// <param name="apiurl">请求的接口</param>
/// <param name="meth">请求方式</param>
/// <param name="param">非系统参数</param>
/// <param name="charset">编码</param>
/// <returns></returns>
public static String GetOpen56APiTest(String apiurl, String meth, String param,String charset)
{
String str = "", PageCode = "", sign=""; appkeyOne = "1000000010"; secretOne = "0e4f13954bc537ec"; Hashtable ht = new Hashtable();
String[] tag={"&"}; String[] ss = param.Split(tag, StringSplitOptions.RemoveEmptyEntries);
if(ss!=null&&ss.Length>0)
{
for (int i = 0; i < ss.Length;i++ )
{
String subPageCode = ss[i].ToString(); String [] tagg = {"="}; String[] ss2 = subPageCode.Split(tagg, StringSplitOptions.RemoveEmptyEntries); if(ss2!=null&&ss2.Length>0)
{
String key = ss2[0].ToString(); String value = ss2[1].ToString(); if(key!=""&&value!="")
{
ht.Add(key, value);
}
}
} sign = signRequest(ht); str = apiurl + "?" + sign; try
{
PageCode = unicode_js_1(GetPageCode(str, charset, meth)).Replace("\\", "");
}
catch (Exception ex)
{
PageCode = ex.ToString();
}
} return PageCode;
}
/// <summary>
/// unicode转中文(符合js规则的)
/// </summary>
/// <returns></returns>
private static string unicode_js_1(string str)
{
string outStr = "";
Regex reg = new Regex(@"(?i)\\u([0-9a-f]{4})");
outStr = reg.Replace(str, delegate(Match m1)
{
return ((char)Convert.ToInt32(m1.Groups[1].Value, 16)).ToString();
});
return outStr;
}
#endregion #region Md5值加密
/// <summary>
/// md5Run16 用md5 16位 加密输入字符串
/// </summary>
/// <param name="strInput">输入字符串 </param>
/// param name="num">md5指示位(16 or 32) </param>
/// <returns>默认返回用md5 16位 加密后的字符串</returns>
private static String md5Run(String strInput, int num)
{
if (strInput != null && strInput != "")
{
string hashedPassword =
FormsAuthentication.HashPasswordForStoringInConfigFile(strInput, "MD5");//md5 32位 if (num == 32)
{
return hashedPassword.ToLower();
}
else
{
string MD5pwd32 = hashedPassword.Substring(8, 16).ToLower();//MD5 32位
}
}
return "";
} private static String signRequest(System.Collections.Hashtable hm)
{ String appkey = appkeyOne; String secret = secretOne; String req = md5Run(mapToString(hm), 32); //第一轮次计算 MD5加密 String sdate2 = System.DateTime.Now.ToString("yyyy-M-d HH:mm:ss"); String sdate1 = "1970-01-01 00:00:00"; System.TimeSpan timespan = Convert.ToDateTime(sdate2) - Convert.ToDateTime(sdate1); Int64 ts = Convert.ToInt64(timespan.TotalSeconds); hm.Add("sign", md5Run(req + "#" + appkey + "#" + secret + "#" + ts, 32)); //第二轮次计算 MD5加密 hm.Add("appkey", appkey); hm.Add("ts", ts); return mapToString(hm);
}
#endregion #region 将 map 中的参数及对应值转换为字符串
private static String mapToString(System.Collections.Hashtable hm)
{
int count = hm.Keys.Count; Object[] array = new Object[count]; hm.Keys.CopyTo(array, 0); System.Array.Sort(array); String str = ""; for (int i = 0; i < array.Count();i++ )
{
String key = array[i].ToString(); if (i !=(array.Count()-1))
{
str += key + "=" + hm[key] + "&";
}
else
{
str += key + "=" + hm[key];
}
}
return str;
}
#endregion #region 获取源码
//获取指定页面的源代码
private static String GetPageCode(String PageURL, String Charset)
{
//存放目标网页的html
String strHtml = "";
try
{ // Uri myUri = new Uri(PageURL);
//连接到目标网页
WebRequest wreq = WebRequest.Create(PageURL);
wreq.Method = "GET";
HttpWebResponse wresp = (HttpWebResponse)wreq.GetResponse(); //采用流读取,并确定编码方式
Stream s = wresp.GetResponseStream();
StreamReader objReader = new StreamReader(s, System.Text.Encoding.GetEncoding(Charset)); string strLine = "";
//读取
while (strLine != null)
{
strLine = objReader.ReadLine();
if (strLine != null)
{
strHtml += strLine.Trim();
}
}
return strHtml;
}
catch (Exception ei) //遇到错误,打印错误
{
return strHtml = ei.ToString();
}
} //获取指定页面的源代码
private static String GetPageCode(String PageURL, String Charset, String meth)
{
//存放目标网页的html
String strHtml = "";
try
{ // Uri myUri = new Uri(PageURL);
//连接到目标网页
WebRequest wreq = WebRequest.Create(PageURL);
if (meth == "" || meth == null)
{
meth = "get";
}
wreq.Method = meth;
HttpWebResponse wresp = (HttpWebResponse)wreq.GetResponse(); //采用流读取,并确定编码方式
Stream s = wresp.GetResponseStream();
StreamReader objReader = new StreamReader(s, System.Text.Encoding.GetEncoding(Charset)); string strLine = "";
//读取
while (strLine != null)
{
strLine = objReader.ReadLine();
if (strLine != null)
{
strHtml += strLine.Trim();
}
}
return strHtml;
}
catch (Exception ei) //遇到错误,打印错误
{
return strHtml = ei.ToString();
}
}
#endregion}