2012年11月29日 星期四

asp 使用三竹簡訊群發的範例


<%@LANGUAGE="VBSCRIPT" CODEPAGE="950"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
<title>無標題文件</title>
</head>

<body>
<%
'讀取檔案內容
Set fs = CreateObject("Scripting.FileSystemObject")
FileName=server.MapPath("testpost.txt")
Set fw = fs.OpenTextFile(FileName,1,true)
SendBody=fw.ReadAll
fw.close
'正式HTTPS
'sendURL="https://smexpress.mitake.com.tw:9601/SmSendPost.asp?username=XXXXX&password=@@@@@@&encoding=UTF8"
'正式HTTP
'sendURL="http://smexpress.mitake.com.tw:9600/SmSendPost.asp?username=SITTest&password=1234&encoding=UTF8"
'測試HTTP
sendURL="http://163.29.39.31:8000/SmSendPost.asp?username=SITTest&password=1234&encoding=UTF8"
Set objWinHttp = Server.CreateObject("WinHttp.WinHttpRequest.5.1")
objWinHttp.Open "POST", sendURL
objWinHttp.SetRequestHeader "Content-Type","application/x-www-form-urlencoded"
'objWinHTTP.Option(2) = 950 '用來忽略SSL憑證的的錯誤
objWinHTTP.Option(4) = &H3300 '用來忽略SSL憑證的的錯誤
objWinHttp.Send SendBody

'處理從Server端送過來的資料
varBinData=objWinHttp.ResponseBody()
varStrData=Bin2Str(varBinData)

response.write varStrData

'Binary資料轉為String
Function Bin2Str(varBinData)
    Dim varlen,clow,cstrc,skipflag
         skipflag=0
    cstrc = ""
    If Not IsNull(varBinData) Then
      varlen=LenB(varBinData)
      For i=1 To varlen
          If skipflag=0 Then
             clow = MidB(varBinData,i,1)
             '判斷是否中文
             If AscB(clow) > 127 Then
                cstrc =cstrc & Chr(AscW(MidB(varBinData,i+1,1) & clow))
                skipflag=1
             Else
                cstrc = cstrc & Chr(AscB(clow))
             End If
          Else
             skipflag=0
          End If
       Next
    End If
    bin2str = cstrc
End Function
%>
<input name="Submit2" type="button" onClick="javascript:window.opener=null;window.open('','_self');window.close();" value="關閉視窗">
</body>
</html>

asp的同目錄下請放testpost.txt如下


[101]
DestName=經理
dstaddr=0938444585
smbody=我是測試預約15:45發送
dlvtime=20121129154500
response=http://192.168.1.200/smreply.asp
[102]
DestName=二寶
dstaddr=0983444555
dlvtime=20121129155000
smbody=我是測試預約15:50發送
[103]
DestName=小明
dstaddr=0983444114
dlvtime=20121129154000
smbody=我是測試預約15:40發送

2012年11月28日 星期三

c# 使用三竹簡訊群發的範例

http://tw.myblog.yahoo.com/wululu-blog/article?mid=170&next=169&l=f&fid=16

把上面這個例子再簡化說明清楚一點

VS新增一個控制台專案 :


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;
using System.Net;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
        string tRequestFilePath = @"D:\\a.ini";
        string tUrl = "http://smexpress.mitake.com.tw:9600/SmSendPost.asp?username=XXXXXXXA&password=11111111&encoding=Big5";
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(tUrl);
        request.Timeout = 1000 * 5;
        request.Method = "POST";
        request.ContentType = "application/x-www-form-urlencoded";
        //撈出發送資料放到tMSG存成格式為ANSI(必須存成INI格式喔)這裡我直接用一個ini檔來簡化這個例子
        // StreamWriter sw = new StreamWriter(tRequestFilePath, true, System.Text.Encoding.Default);
        // sw.Write(tMSG.ToString());
        // sw.Close();
        //再讀出來
        StreamReader sr = new StreamReader(tRequestFilePath, System.Text.Encoding.Default);
        string strTest = sr.ReadToEnd();
        sr.Close();
        //轉成byte格式
        Byte[] B = System.Text.Encoding.Default.GetBytes(strTest);
        request.ContentLength = B.Length;
        System.IO.Stream ioStream = request.GetRequestStream(); //開始提交數據
        ioStream.Write(B, 0, B.Length);
        ioStream.Close();
        //取得回來訊息
        HttpWebResponse response = request.GetResponse() as HttpWebResponse;
        StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.Default);
        string tReturn = reader.ReadToEnd();
        //可以輸出 或存檔tReturn

        Console.WriteLine(tReturn);
        Console.ReadKey();

        reader.Close();        }
    }
}

D:\\a.ini (ansi格式)內容如下


[101]
DestName=經理
dstaddr=0980944485
smbody=我是測試1
response=http://192.168.1.200/smreply.asp
[102]
DestName=二寶
dstaddr=0982944445
smbody=我是測試2
[103]
DestName=小明
dstaddr=0981444444
smbody=我是測試3



2012年11月25日 星期日

ASP表單中關於Enter鍵的控管

處理方式的其中兩種 :
1. 將所有input的Enter鍵模擬成預設按鈕觸發(適用於查詢頁面)

<script>
//menphis 2012.11.26 setting default click button(參考自訊光公司網頁)
$(document).ready(function() {
$("input").bind("keydown", function(event) {
// track enter key
var keycode = (event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode));
if (keycode == 13) { // keycode for enter key
document.getElementById('Mybutton').click();
return false;
} else {
return true;
}
}); // end of function
}); // end of document ready
</script>
2.將input的Enter鍵模擬成Tab鍵(適用於表單內容維護)

所有Input的td中增加 
onkeydown="MyKeyDown();"
並增加以下Function
function 
MyKeyDown(){
if(event.keyCode==13)
event.keyCode=9;
}