C#读取PDF文档文字内容 - tzdk - 博客园

mikel阅读(1465)

来源: C#读取PDF文档文字内容 – tzdk – 博客园

C#读取PDF文档文字内容

通过iTextSharp读取PDF文件内容,下载地址,下载后解压itextsharp-dll-core.zip。

只能读取英文和数字,文档中包含的汉字无法正常读取:

复制代码
private string ReadPdfContent(string filepath)  
{  
    try  
    {  
        string pdffilename = filepath;  
        PdfReader pdfReader = new PdfReader(pdffilename);  
        int numberOfPages = pdfReader.NumberOfPages;  
        string text = string.Empty;  
  
        for (int i = 1; i <= numberOfPages; ++i)  
        {  
            byte[] bufferOfPageContent = pdfReader.GetPageContent(i);  
            text += System.Text.Encoding.UTF8.GetString(bufferOfPageContent);  
        }  
        pdfReader.Close();  
  
        return text;  
    }  
    catch (Exception ex)  
    {  
        StreamWriter log = File.AppendText(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase+"\\log.log");  
        log.WriteLine("出错文件:" + e.FullPath + "原因:" + ex.ToString());  
        log.Flush();  
        log.Close();return null;  
    } 
}
复制代码

 

可以读取中英文

复制代码
private string OnCreated(string filepath)  
{  
    try  
    {  
        string pdffilename = filepath;  
        PdfReader pdfReader = new PdfReader(pdffilename);  
        int numberOfPages = pdfReader.NumberOfPages;  
        string text = string.Empty;  
  
        for (int i = 1; i <= numberOfPages; ++i)  
        {  
            iTextSharp.text.pdf.parser.ITextExtractionStrategy strategy = new iTextSharp.text.pdf.parser.SimpleTextExtractionStrategy();
            text += iTextSharp.text.pdf.parser.PdfTextExtractor.GetTextFromPage(pdfReader, i, strategy);
        }  
        pdfReader.Close();  
  
        return text;  
    }  
    catch (Exception ex)  
    {  
        StreamWriter wlog = File.AppendText(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase+"\\mylog.log");  
        wlog.WriteLine("出错文件:" + e.FullPath + "原因:" + ex.ToString());  
        wlog.Flush();  
        wlog.Close();return null;  
    }  
  
}
复制代码

 

谷歌推出了有意思的 “Just A Line” AR 应用

mikel阅读(1116)

来源: 谷歌推出了有意思的 “Just A Line” AR 应用

谷歌经常用新技术做一些稀奇古怪的实验应用。“Just a Line” 是一款新推出的 AR 应用,建立在谷歌的 ARCore 技术之上。这个应用的设计想法非常简单,但它的成效实际上非常有趣。

“Just A Line” 是一个 AR 实验项目,你可以利用 AR 技术进行简单的绘画,然后用一个简短的视频分享你的创作。触摸屏幕即可开始绘制,点击拍摄按钮并分享你用 #justaline 做了什么。Just A Line 在任何支持 AR Core 的设备上均可用。

想了解更多信息,请访问 g.co/ARExperiments。

您也可以在 https://github.com/googlecreativelab/ar-drawing-java 找到该项目的开源代码。

在应用中,用户只需透过相机拍摄周围的世界,再点击屏幕就可以开始进行虚拟绘画。使用 Just a Line 进行的小创作都可以被保存在手机上,如果你的设备与 ARCore 兼容,不妨下载这个应用玩玩看。

from:青亭

解决IIS7中出现An error occurred on the server when processing the URL错误提示的方法 - yuhaibin168的专栏 - CSDN博客

mikel阅读(695)

来源: 解决IIS7中出现An error occurred on the server when processing the URL错误提示的方法 – yuhaibin168的专栏 – CSDN博客

解决IIS7中出现An error occurred on the server when processing the URL错误提示的方法

前提在ie选项中去掉  显示友好HTTP页面信息
在IIS7上调试程序时,如果程序有错误,默认情况下,会提示:An error occurred on the server when processing the URL. Please contact the system administrator.

在IIS7上调试程序时,如果程序有错误,默认情况下,会提示:

An error occurred on the server when processing the URL. Please contact the system administrator.

If you are the system administrator please click here to find out more about this error.

其实这是IIS7对ASP程序发送的一个脚本错误信息,只要是程序中有错误,就会出现这样的提示。下面的方法是将具体的错误信息显示出来。

一、打开 Internet 信息服务(IIS)管理器。点击出错的站点,并双击右边的ASP图标,如下图所示:

 

二、展开右侧配置中的“调试属性”,把“将错误发送到浏览器”的值设为 “true”,如图所示:

 

题外话:一般ASP程序中,建议将启用父路径设为True,

通过Global.asax文件里面的Session_End事件记录用户退出 (or session timeout) - liangzi4000 - 博客园

mikel阅读(1087)

来源: 通过Global.asax文件里面的Session_End事件记录用户退出 (or session timeout) – liangzi4000 – 博客园

Session.Abandon()和timeout会触发Global.asax的Session_End事件。可以通过这个事件来记录用户退出或者session timeout,这样每个用户都会有一条登陆和退出记录。

退出登陆调用方法:

1
2
3
4
5
public void PerformLogout()
{
    HttpContext.Current.Session["PerformLogout"] = true;
    HttpContext.Current.Session.Abandon();
}

Session_End事件代码:

1
2
3
4
5
6
7
8
9
10
11
protected void Session_End(Object sender, EventArgs e)
{
    BusinessContext bizContext = (BusinessContext)Session["BusinessContext"];
    string loginID = string.IsNullOrEmpty(bizContext.LoginID) ? "" : bizContext.LoginID;
    string title = "Timeout";
    if (Convert.ToBoolean(Session["PerformLogout"]))
    {
        title = "Logout";
    }
    BusinessEvent.Log(BizLogCategory.SECURITY, BizLogModule.USER_AUTHENTICATION, title, "[PerformLogout]Logout Successfully""LoginID: " + loginID, bizContext);
}

有如下几点需要注意:

1. 尽管我们先调用Session.Abandon(),但是在Session_End事件里还是可以继续访问所有session的值。正是因为这个,所以我们可以在PerformLogout方法中给Session[“PerformLogout”]赋值,然后通过这个值来判断Session_End事件是由用户登出触发还是由session timeout触发。

2. ASP.NET里面Session和HttpContext.Current.Session对象都指向System.Web.SessionState.HttpSessionState,大部分地方这两个对象可以互换使用,但是在Session_End事件里,HttpContext.Current返回的是null,所以只能通过Session对象来访问session值。为什么要这样写,参考这里

3. 引起session timeout的设置比较多,测试过的有web.config里面的sessionState timeout, IIS Application Pools的Idle Time-out, IIS Application Pools Recycle, Stop website, 修改web.config等。

 

https://msdn.microsoft.com/en-us/library/system.web.sessionstate.sessionstatemodule.end(v=vs.110).aspx
https://msdn.microsoft.com/en-us/library/system.web.sessionstate.httpsessionstate.abandon(v=vs.110).aspx
http://forums.ASP.NET/t/1275683.aspx?Can+t+access+to+Session+variable+inside+Session_End+Event
http://stackoverflow.com/questions/940742/difference-between-session-and-httpcontext-current-session
http://stackoverflow.com/questions/27657773/why-is-httpcontext-current-null-during-the-session-end-event
http://stackoverflow.com/questions/19509672/why-is-httpcontext-current-null
http://stackoverflow.com/questions/12294532/asp-net-values-of-session-variables-in-session-end-event
https://msdn.microsoft.com/en-us/library/system.web.sessionstate.httpsessionstate.abandon.aspx
https://msdn.microsoft.com/en-us/library/system.web.sessionstate.sessionstatemodule.end.aspx
http://stackoverflow.com/questions/13264212/on-session-timeout-capture-info
http://www.beansoftware.com/ASP.NET-Tutorials/Find-If-Session-Expired.aspx

[C#][ASP.NET MVC]處理Session Timeout - 程序新青年 - 博客园

mikel阅读(1788)

来源: [C#][ASP.NET MVC]處理Session Timeout – 程序新青年 – 博客园

Session Timeout導回登入頁面這樣的功能大家應該並不陌生,

而處理Session  Timeout也有很多方式(也不一定要導回登入頁面),

可以使用client script固定時間輪詢Server(callback)不讓Session Timeout也是一種方法,

在MVC中個人較愛操作Action Filters(比較能展現MVC在設計上的特性~XD),

這裡自己紀錄一下。

 

新增自訂類別並繼承ActionFilterAttribute

public class CheckSessionFilterAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuting( ActionExecutingContext filterContext )
        {
            HttpContext httpcontext = HttpContext.Current;
            // 確認目前要求的HttpSessionState
            if( httpcontext.Session != null )
            {
                //確認Session是否為新建立
                if( httpcontext.Session.IsNewSession )
                {
                    //確認是否已存在cookies
                    String sessioncookie = httpcontext.Request.Headers[ "Cookie" ];
                    if( ( sessioncookie != null ) && ( sessioncookie.IndexOf( "ASP.NET_SessionId" ) >= 0 ) )
                    {
                        Logon( filterContext );
                    }
                }
            }
            base.OnActionExecuting( filterContext );
}
        private void Logon( ActionExecutingContext filterContext )
        {
            RouteValueDictionary dictionary = new RouteValueDictionary
                ( new
                {
                    controller = "Account",
                    action = "Logon",
                    returnUrl = filterContext.HttpContext.Request.RawUrl
                } );
            filterContext.Result = new RedirectToRouteResult( dictionary );
        }
    }

Controller

public ActionResult Index()
        {
            Session[ "mytime" ] = DateTime.Now.ToString();
            ViewData[ "Message" ] = Session[ "mytime" ] as String;
            return View();
        }
        [CheckSessionFilterAttribute]//自訂Action Filters
        public ActionResult About()
        {
return View();
   }

Web.config

image

設定2分鐘Session timeout。

結果:

image

2分鐘過後點擊About。

image

導回登入頁面。

Asp.net Mvc+MongoDB+Autofac等打造轻量级blog系统(一) - Nic Pei - 博客园

mikel阅读(1098)

来源: Asp.net Mvc+MongoDB+Autofac等打造轻量级blog系统(一) – Nic Pei – 博客园

这两天坐地铁上在想着是否可以做一个很轻量级的.net博客发布系统。。。所有东西都用轻量级的,我想要系统是基于ASP.NET Mvc框架的,所以选定了如下几个大的组件来完成这个设想。

1. 整个应用程序架构:ASP.NET mvc 3 (Razor)

2.数据存储 : MongoDB,是个面向文档的数据库,它是多系统支持,轻量级,高性能的。

3.ORM : 现在的应用开发如果你不用ORM,那就好像有点老土了,但是ORM永远都无法和ado.net媲美,无乱是EF,NHibernate还是linq等等。。。。而我这里还是想使用一个ORM工具,于是选择了Simple.Data这个非常轻量级的ORM工具,它使用了C# 中的Dynamic特性。

4.IoC工具,绝对是autofac这个最轻量级了。。。

 

对于ASP.NET MVC你可以到这里看到很多学习资料:http://www.cnblogs.com/n-pei/tag/Asp.net%20MVC/

包括ASP.NET MVC 3的系列文章。。。。微笑

 

环境的要求:

1.首先你需要的是.net framework 4的安装。你机器不需要安装ASP.NET MVC,只需要把对应的几个dll添加到bin目录下就行。

 

2.MongoDB的安装 如果你以前接触过MongoDB,请跳过这一段,直接看第三步。

image

 

http://www.mongodb.org/ 它的数据是以json格式存储的。

下载到对应的压缩包,然后解压到某个盘下。

image

默认的mongo是不会自己创建文件夹,而它却需要找到指定的文件夹Data\db,所以我们需要在bin目录所在的根文件夹下创建如下文件夹:

image

 

接下来就是运行db server了。

image

 

现在数据库服务器就开始运行了,因为它是在dos下运行的,所以不能关闭这个窗口,以后说明下如何把它制定为windows service,这样就需要开着窗口了。

 

3.ORM: Simple.Data这个是使用C# Dynamic属性的轻量级ORM工具,它不是很好用,但是速度是挺快的,而且不需要配置文件,支持各种数据库。。。

你可以到这里下载:http://github.com/markrendle/Simple.Data

image

 

4. IoC工具,这个Autofac我之前有好多文章都介绍了。你可以到这里下载和查看:http://code.google.com/p/autofac/

我博客中相关的文章: http://www.cnblogs.com/n-pei/tag/Autofac/

 

 

可能你已经不耐烦了,,我啰嗦这么多,,好吧,接下来开始使用MogonDB,这篇文章主要介绍如何在asp.net mvc中使用它。。。。其它模块在以后的文章中介绍。

 

首先是创建实体,这里只创建好Post和comment两个实体。

image

接下来是创建Repository模块:

Post的Repository接口:

image

对应的Save方法:

image

这里的操作都是比较繁琐的,以后会结合autofac优化这一部分。

GetAll方法和通过Id得到某个post实体的方法如下:

image

 

 

 

 

还有一部分是update某个post.这部分代码就不贴了。

 

接下来是Controller部分的代码:

Create post部分的代码:

image

添加对应的View以后,运行:

image

点击Craete按钮后:

image

保存成功,然后会自动跳转到List页面:

image

 

稍候等整个项目写的差不多了,我会把代码放到codeplex上,支持下微软,呵呵。

 

asp.net mvc 接入阿里大于 短信验证码发送 - 邹柯 - 博客园

mikel阅读(1303)

来源: asp.net mvc 接入阿里大于 短信验证码发送 – 邹柯 – 博客园

项目前端页面实例

第1步:登录阿里大于控制台

https://www.alidayu.com/center/user/account?spm=0.0.0.0.P1K1jG

第2步:创建应用

第3步:配置短信签名

第4步:配置短信模板

第5步:前端

<tr class=”margin-top”> <td class=”padding-top text-center”>手机号</td> <td><input type=”text” class=”inputs” id=”Phone” name=”Phone”> </td> <td><input type=”button” value=”获取验证码” id=”sms” onclick=”sendemail()”></td> </tr> <tr> <td class=”padding-top text-center”>验证码</td> <td><input type=”text” class=”inputs” id=”Code” name=”Code”></td> </tr>

第6步:js处理

$(function () { $(“#sms”).click(function () { sendCode($(“#sms”)); }); v = getCookieValue(“secondsremained”);//获取cookie值 if (v > 0) { settime($(“#sms”));//开始倒计时 } }) //发送验证码 function sendCode(obj) { var phoneNumber = $(“#Phone”).val(); var result = isPhoneNum(phoneNumber); if (result) { //将手机利用ajax提交到后台的发短信接口 $.post(“/College/Code”, { Phone: phoneNumber }, function (data) { if (data == “ok”) { alert(“验证码发送成功!”); } else { alert(“验证码发送失败,请重新发送!”); } }); addCookie(“secondsremained”, 60, 60);//添加cookie记录,有效时间60s settime(obj); //开始倒计时 } } //开始倒计时 var countdown; function settime(obj) { countdown = getCookieValue(“secondsremained”); if (countdown == 0) { obj.removeAttr(“disabled”); obj.val(“获取验证码”); return; } else { obj.attr(“disabled”, true); obj.val(“重新发送(” + countdown + “)”); countdown–; editCookie(“secondsremained”, countdown, countdown + 1); } setTimeout(function () { settime(obj) }, 1000) //每1000毫秒执行一次 } //校验手机号是否合法 function isPhoneNum(phoneNumber) { var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/; if (!myreg.test(phoneNumber)) { alert(‘请输入有效的手机号码!’); return false; } else { return true; } } //发送验证码时添加cookie function addCookie(name, value, expiresHours) { var cookieString = name + “=” + escape(value); //判断是否设置过期时间,0代表关闭浏览器时失效 if (expiresHours > 0) { var date = new Date(); date.setTime(date.getTime() + expiresHours * 1000); cookieString = cookieString + “;expires=” + date.toUTCString(); } document.cookie = cookieString; } //修改cookie的值 function editCookie(name, value, expiresHours) { var cookieString = name + “=” + escape(value); if (expiresHours > 0) { var date = new Date(); date.setTime(date.getTime() + expiresHours * 1000); //单位是毫秒 cookieString = cookieString + “;expires=” + date.toGMTString(); } document.cookie = cookieString; } //根据名字获取cookie的值 function getCookieValue(name) { var strCookie = document.cookie; var arrCookie = strCookie.split(“; “); for (var i = 0; i < arrCookie.length; i++) { var arr = arrCookie[i].split(“=”); if (arr[0] == name) { return unescape(arr[1]); break; } else { return “”; break; } } }

第7步:后台控制器处理

#region 商学院报名发送验证码 public ActionResult ValidateCode() { string Code = GetRandomString(6); string url = “https://eco.taobao.com/router/rest”; string appkey = “****”; //此处填写你自己的 string secret = “****”; //此处填写你自己的 ITopClient client = new DefaultTopClient(url, appkey, secret); AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest(); req.Extend = “”; //可空,返回状态 req.SmsType = “normal”; //不可更改 req.SmsFreeSignName = “个人小站”; //申请的短信签名,不可填写与申请的不一 req.SmsParam = “{VCode:'” + Code + “‘}”; //模板内参数必填 req.RecNum = Request[“Phone”]; //接收者手机号码 req.SmsTemplateCode = “SMS_74235011”; //短信模板的编号,不可出错 AlibabaAliqinFcSmsNumSendResponse rsp = client.Execute(req); if (rsp.IsError == false) { Console.WriteLine(rsp.Body); //return Content(rsp.Body); } //将验证码设置缓存 var CodeInfo = (Object)Code; CacheOpt.SetCache(“Code”, CodeInfo, Convert.ToInt32(60)); return Content(“ok”); } #region 生成6位验证码 public string GetRandomString(int iLength) { string buffer = “0123456789”; // 随机字符中也可以为汉字(任何) StringBuilder sb = new StringBuilder(); Random r = new Random(); int range = buffer.Length; for (int i = 0; i < iLength; i++) { sb.Append(buffer.Substring(r.Next(range), 1)); } return sb.ToString(); } #endregion

第8步:缓存处理

public class CacheOpt { /// <summary> /// 设置缓存 /// </summary> /// <param name=”CacheKey”></param> /// <param name=”objObject”></param> /// <param name=”Seconds”>超过多少秒后过期</param> public static void SetCache(string CacheKey, object objObject, long Seconds) { System.Web.Caching.Cache objCache = HttpRuntime.Cache; objCache.Insert(CacheKey, objObject, null, System.DateTime.Now.AddSeconds(Seconds), TimeSpan.Zero); } /// <summary> /// 获取数据缓存 /// </summary> /// <param name=”CacheKey”>键</param> public static object GetCache(string CacheKey) { System.Web.Caching.Cache objCache = HttpRuntime.Cache; return objCache[CacheKey]; } }

注:完整版项目地址:http://www.gmkcn.com/

asp.net C# 实现阿里大鱼和云片网短信接口类 - 叶长种 - 博客园

mikel阅读(848)

来源: asp.net C# 实现阿里大鱼和云片网短信接口类 – 叶长种 – 博客园

云片网短信通用类

复制代码
public class YunpianSMS
    {
        public YunpianSMS()
        { }

        /// <summary>
        /// 服务器HTTP地址
        /// </summary>
        private static string BASE_URI = "http://yunpian.com";

        /// <summary>
        /// 服务版本号
        /// </summary>      
        private static string VERSION = "v1";

        /// <summary>
        /// 查账户信息的http地址 
        /// </summary>           
        private static string URI_GET_USER_INFO = BASE_URI + "/" + VERSION + "/user/get.json";

        /// <summary>
        /// 通用接口发短信的http地址 
        /// </summary>
        private static string URI_SEND_SMS = BASE_URI + "/" + VERSION + "/sms/send.json";

        /// <summary>
        /// 模板接口短信接口的http地址 
        /// </summary>
        private static string URI_TPL_SEND_SMS = BASE_URI + "/" + VERSION + "/sms/tpl_send.json";

        /// <summary>
        /// 通用接口查回复的短信的http地址 
        /// </summary>
        private static string URI_GET_REPLY = BASE_URI + "/" + VERSION + "/sms/get_reply.json";

        /// <summary>
        /// APIKEY
        /// </summary>
        private static string APIKEY = "APIKEY";

        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <returns>Json格式</returns>
        public static string GetUserInfo()
        {
            System.Net.WebRequest req = System.Net.WebRequest.Create(URI_GET_USER_INFO + "?apikey=" + APIKEY);
            System.Net.WebResponse resp = req.GetResponse();
            System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
            return sr.ReadToEnd().Trim();
        }

        /// <summary>
        ///  发短信通用接口
        /// </summary>
        /// <param name="text">短信内容</param>
        /// <param name="mobile">接收的手机号码,有多个手机号则用逗号分隔,一次最多100个手机号码</param>
        /// <returns>Json格式</returns> 
        public static string SendSms(string text, string mobile)
        {
            //注意:参数必须进行Uri.EscapeDataString编码。以免&#%=等特殊符号无法正常提交
            string parameter = "apikey=" + APIKEY + "&mobile=" + mobile + "&text=" + text;
            return HttpPost(URI_SEND_SMS, parameter);
        }

        /// <summary>
        /// 模板接口发短信
        /// </summary>
        /// <param name="tpl_id">模板ID</param>
        /// <param name="mobile">接收的手机号码</param>
        /// <param name="tpl_value">模板变量值</param>
        /// <returns>Json格式</returns>
        public static string TplSendSms(long tpl_id, string mobile, string tpl_value)
        {
            string postDataStr = "apikey=" + APIKEY + "&mobile=" + mobile + "&tpl_id=" + tpl_id.ToString() + "&tpl_value=" + tpl_value;
            return HttpPost(URI_TPL_SEND_SMS, postDataStr);
        }

        /// <summary>
        /// 查回复的短信
        /// </summary>
        /// <param name="page_num">页码,从1开始</param>
        /// <param name="page_size">每页个数,最大100个</param>
        /// <param name="mobile">接收的手机号码</param>
        /// <returns>Json格式</returns>
        public static string GetReplySms(int page_num, int page_size, string mobile,string datastart,string dataend)
        {
            DateTime now = DateTime.Now;
            //string datastart = now.AddDays(-3).ToString("yyyy-MM-dd 00:00:00");
            //string datasend = now.AddDays(1).ToString("yyyy-MM-dd 00:00:00");
            string postDataStr = "apikey=" + APIKEY + "&start_time=" + datastart + "&end_time=" + dataend
                + "&page_num=" + page_num + "&page_size=" + page_size + "&mobile=" + mobile;

            return HttpPost(URI_GET_REPLY, postDataStr);
        }

        /// <summary>
        /// 通用接口请求
        /// </summary>
        /// <param name="Url"></param>
        /// <param name="postDataStr"></param>
        /// <returns></returns>
        public static string HttpPost(string Url, string postDataStr)
        {
            byte[] dataArray = Encoding.UTF8.GetBytes(postDataStr);
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = dataArray.Length;
            //request.CookieContainer = cookie;
            Stream dataStream = request.GetRequestStream();
            dataStream.Write(dataArray, 0, dataArray.Length);
            dataStream.Close();
            try
            {
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                String res = reader.ReadToEnd();
                reader.Close();
                return res;
            }
            catch (Exception e)
            {
                return e.Message + e.ToString();
            }
        }
    }
复制代码

调用短信模版方式:

复制代码
string tpl_value = HttpUtility.UrlEncode(
                            HttpUtility.UrlEncode("#username#", Encoding.UTF8) + "=" +
                            HttpUtility.UrlEncode(phone, Encoding.UTF8) + "&" +
                            HttpUtility.UrlEncode("#passwd#", Encoding.UTF8) + "=" +
                            HttpUtility.UrlEncode(passwd, Encoding.UTF8), Encoding.UTF8);
                        //短信失败时,调用第二短信接口
                        YunpianSMS.TplSendSms(1508914, phone, tpl_value);
复制代码

阿里大鱼短信通用类

复制代码
public class AliDaYuSMS
    {
        /// <summary>
        /// <summary>
        /// Url
        /// </summary>
        private static string Url = "http://gw.api.taobao.com/router/rest";
        /// AppKey
        /// </summary>
        private static string AppKey = "AppKey";
        /// <summary>
        /// AppSecret
        /// </summary>
        private static string AppSecret = "AppSecret";

        /// <summary>
        ///  发短信通用接口
        /// </summary>
        /// <param name="extend">公共回传参数,
        /// 在“消息返回”中会透传回该参数;举例:用户可以传入自己下级的会员ID,在消息返回时,
        /// 该会员ID会包含在内,用户可以根据该会员ID识别是哪位会员使用了你的应用</param>
        /// <param name="smsFreeSignName">短信签名</param>
        /// <param name="code">短信模板ID</param>
        /// <param name="smsParam">短信模板变量“验证码${code},您正在进行${product}身份验证,打死不要告诉别人哦!”,
        /// 传参时需传入{"code":"1234","product":"alidayu"}</param>
        /// <param name="mobile">接收的手机号码,群发短信需传入多个号码,以英文逗号分隔,一次调用最多传入200个号码。</param>
        /// <returns>Json格式</returns> 
        public static string SendSms(string extend, string smsFreeSignName, string code, string smsParam, string mobile)
        {
            ITopClient client = new DefaultTopClient(Url, AppKey, AppSecret);
            AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
            req.Extend = extend;
            req.SmsType = "normal";
            req.SmsFreeSignName = smsFreeSignName;
            req.SmsParam = smsParam;
            req.RecNum = mobile;
            req.SmsTemplateCode = code;
            AlibabaAliqinFcSmsNumSendResponse rsp = client.Execute(req);
            return rsp.SubErrMsg;
        }
    }

调用方式

                    var smsresult = AliDaYuSMS.SendSms(phone, "潮运动", "SMS_13000621", "{\"username\":\"" + phone + "\",\"passwd\":\"" + passwd + "\"}", phone);
复制代码

 

git 使用简易指南

mikel阅读(1078)

来源: git 使用简易指南

git – 简易指南

助你开始使用 git 的简易指南,木有高深内容,;)。

作者:罗杰·杜德勒
感谢:@tfnico@fhd and Namics
其他语言 englishdeutschespañolfrançaisitalianonederlandsportuguêsрусскийtürkçe,
မြန်မာ日本語한국어
如有纰漏,请到 github 填报

创建新仓库

创建新文件夹,打开,然后执行
git init
以创建新的 git 仓库。

检出仓库

执行如下命令以创建一个本地仓库的克隆版本:
git clone /path/to/repository
如果是远端服务器上的仓库,你的命令会是这个样子:
git clone username@host:/path/to/repository

工作流

你的本地仓库由 git 维护的三棵“树”组成。第一个是你的 工作目录,它持有实际文件;第二个是 缓存区(Index),它像个缓存区域,临时保存你的改动;最后是 HEAD,指向你最近一次提交后的结果。

添加与提交

你可以计划改动(把它们添加到缓存区),使用如下命令:
git add <filename>
git add *
这是 git 基本工作流程的第一步;使用如下命令以实际提交改动:
git commit -m "代码提交信息"
现在,你的改动已经提交到了 HEAD,但是还没到你的远端仓库。

推送改动

你的改动现在已经在本地仓库的 HEAD 中了。执行如下命令以将这些改动提交到远端仓库:
git push origin master
可以把 master 换成你想要推送的任何分支。

如果你还没有克隆现有仓库,并欲将你的仓库连接到某个远程服务器,你可以使用如下命令添加:
git remote add origin <server>
如此你就能够将你的改动推送到所添加的服务器上去了。

分支

分支是用来将特性开发绝缘开来的。在你创建仓库的时候,master 是“默认的”。在其他分支上进行开发,完成后再将它们合并到主分支上。

创建一个叫做“feature_x”的分支,并切换过去:
git checkout -b feature_x
切换回主分支:
git checkout master
再把新建的分支删掉:
git branch -d feature_x
除非你将分支推送到远端仓库,不然该分支就是 不为他人所见的
git push origin <branch>

更新与合并

要更新你的本地仓库至最新改动,执行:
git pull
以在你的工作目录中 获取(fetch) 并 合并(merge) 远端的改动。
要合并其他分支到你的当前分支(例如 master),执行:
git merge <branch>
两种情况下,git 都会尝试去自动合并改动。不幸的是,自动合并并非次次都能成功,并可能导致 冲突(conflicts)。 这时候就需要你修改这些文件来人肉合并这些 冲突(conflicts) 了。改完之后,你需要执行如下命令以将它们标记为合并成功:
git add <filename>
在合并改动之前,也可以使用如下命令查看:
git diff <source_branch> <target_branch>

标签

在软件发布时创建标签,是被推荐的。这是个旧有概念,在 SVN 中也有。可以执行如下命令以创建一个叫做 1.0.0 的标签:
git tag 1.0.0 1b2e1d63ff
1b2e1d63ff 是你想要标记的提交 ID 的前 10 位字符。使用如下命令获取提交 ID:
git log
你也可以用该提交 ID 的少一些的前几位,只要它是唯一的。

替换本地改动

假如你做错事(自然,这是不可能的),你可以使用如下命令替换掉本地改动:
git checkout -- <filename>
此命令会使用 HEAD 中的最新内容替换掉你的工作目录中的文件。已添加到缓存区的改动,以及新文件,都不受影响。

假如你想要丢弃你所有的本地改动与提交,可以到服务器上获取最新的版本并将你本地主分支指向到它:
git fetch origin
git reset --hard origin/master

有用的贴士

内建的图形化 git:
gitk
彩色的 git 输出:
git config color.ui true
显示历史记录时,只显示一行注释信息:
git config format.pretty oneline
交互地添加文件至缓存区:
git add -i

解决Git建立远程分支关联时fatal the current branch master has no upstream branch 问题 - 拂晓的专栏 - CSDN博客

mikel阅读(3611)

来源: 解决Git建立远程分支关联时fatal the current branch master has no upstream branch 问题 – 拂晓的专栏 – CSDN博客

问题描述
今天在使用git时,在本地新建了一个分支,按照网上搜到的方式使用 git branch –set-upstream dev origin/dev (这里的dev为本地新建的分支)命令建立本地分支与远程分支的关联,但该命令执行后并不能成功push变更到远程分支。

问题解决
出现上述问题,说明远程并没有感知到本地新建的这个分支,经过多种尝试后,发现一旦执行 git branch –set-upstream 命令后本地与远程的关联要是仍旧没有建立成功,则再次执行 git push -u origin dev 即可成功建立本地与远程的关联。

git push -u origin dev