JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java SE 討論區 » 網路程式設計  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友   
reply to postflat modego to previous topicgo to next topic
本主題所含的標籤
作者 元大證券下單API使用COM元件的問題
yuwenche





發文: 4
積分: 0
於 2017-05-31 01:00 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
元大證券的下單API是使用COM(Component Object Model)元件. 我已經能用excel的VBA登入,並接收到成功登入的訊息.而我改用Java來寫時,雖然也有收到伺服器端的訊息, 但卻一直無法接收到成功登入的訊息.程式如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
 
public class yuanta_order {
    
   
    public static void main(String[] args) {
        
      try{
        ActiveXComponent ord = new ActiveXComponent("Yuanta.YuantaOrdCtrl.64");//jacob.dll在jdk\bin
        Dispatch order = (Dispatch) ord.getObject();
        
        Variant aa = Dispatch.call(order, "SetFutOrdConnection", new Variant("ID"),new Variant(password),new Variant("api.yuantafutures.com.tw"),new Variant(80)); //程式內沒寫回傳值,但log內仍有return: 3
        //int ret = Dispatch.call(order, "SetFutOrdConnection", new Variant[]{new Variant("ID"),new Variant(password),new Variant("api.yuantafutures.com.tw"),new Variant(80)}).toInt();//可return: 3
        
        //System.out.println(aa.TLinkStatus);//編譯錯誤,找不到TLinkStatus      
        //System.out.println(ret);//只印出 3
     
       
      }catch(Exception e){
          System.out.println("error");
      }
    }
    
}

第1~3行引用jacob套件
第11行的 Yuanta.YuantaOrdCtrl.64 為註冊表內的ProgID
第14~15行均有回傳值3(連線中),但無法收到連線成功的其它訊息, 應會回傳2(登入成功),帳號等.

另外附上VBA的程式
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
Private Sub CommandButton1_Click()
   Dim result As Long
   
   result = YuantaOrd1.SetFutOrdConnection("ID", "password", "api.yuantafutures.com.tw", "80")
   Cells(16, 3) = Now & ":" & CStr(result)
   
End Sub
 
Private Sub YuantaOrd1_OnLogonS(ByVal TLinkStatus As Long, ByVal AccList As String, ByVal Casq As String, ByVal Cast As String)
    
    Cells(19, 3) = TLinkStatusRtnCn(TLinkStatus)
    Cells(20, 3) = AccList
    Cells(21, 3) = Casq
    Cells(22, 3) = Cast
    
End Sub
 
Private Function TLinkStatusRtnCn(ByVal TLinkStatus As Long) As String
 
Dim retString As String
 
    retString = "[" & CStr(TLinkStatus) & "]"
    
    Select Case TLinkStatus
        Case 0:
            retString = retString & " 未進行連線"
        Case 1:
            retString = retString & " lsConnected LinkReady"
        Case 2:
            retString = retString & " 登入成功"
        Case 3:
            retString = retString & " 線路連線中"
        Case 4:
            retString = retString & " 無效憑證"
         Case Else
            retString = retString & " 未知錯誤"
    End Select


請有相關經驗的先進, 能給予指引或方向.


reply to postreply to post
話題樹型展開
人氣 標題 作者 字數 發文時間
1002 元大證券下單API使用COM元件的問題 yuwenche 2403 2017-05-31 01:00
867 Re:元大證券下單API使用COM元件的問題 yuwenche 92 2017-07-06 06:17
» JWorld@TW »  Java SE 討論區 » 網路程式設計

reply to postflat modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8