Agigi Wang
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
Invitee
Publish Note

Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

Your note will be visible on your profile and discoverable by anyone.
Your note is now live.
This note is visible on your profile and discoverable online.
Everyone on the web can find and read all notes of this public team.
See published notes
Unpublish note
Please check the box to agree to the Community Guidelines.
View profile
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Emoji Reply
Enable
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
使用Wine來跑群益API === ###### tags: `程式相關` `財金相關` # 安裝步驟 - 先根據[Wine的使用方法與心得](https://hackmd.io/dhU67tClQCeuL36-8NztLA)這一篇文章來安裝Ubuntu 32bit的環境以及安裝Wine。要確定Wine與`winetricks`要確實安裝完成! - 要注意Wine官方強烈不建議使用者用root來執行Wine!而Wine的程式最好是在X Window的環境下執行! - 接下來首先先來設定Wine的環境,也就是Wine的Windows小系統含DLL檔要放在哪個資料夾下。 - 先使用`遠端桌面連線`來登入X Window環境! - 再來打開Terminal,執行以下指令以設定Wine的環境! ``` $ export WINEPREFIX=~/.wine #這一行其實不需要,這一行在Ubuntu 64bit的環境才會一定需要! $ export WINEARCH=win32 #這一行其實不需要,這一行在Ubuntu 64bit的環境才會一定需要! $ wineboot #創建Wine的環境在~/.wine/資料夾下! (它若是詢問要不要裝Wine Mono和Gecko,就直接安裝了!) ``` - 接下來需要透過`winetricks`來安裝群益API需要的套件! - `vcrun2010`是VC++ 2010的可轉散發套件,是群益API的SKCOM.dll檔需要的! - `vcrun2015`是VC++ 2015的可轉散發套件,是因為我有使用Visual C++ 2015來編譯一個簡單的程式!([程式碼參考來源](http://kwedr.blogspot.com/2017/07/api-c-atl.html)) 我幾乎照抄,只有最下面的`6111`換成`TX00`(也就是台指期),然後帳號密碼換成自己的! - 注意!這個原始碼千萬不要使用Visual C++ 2010去build!因為Visual C++ 2010太舊了!它裡面用到的`queue.h`還要額外自己上網下載來patch在Visual C++ 2010上!`queue.h`它很大包,我沒有成功,超級麻煩的!`queue.h`到Visual C++ 2012才被Visual Studio官方正式支援! - `dotnet40`是 .NET Framework 4.0,是為了Visual C#而裝的!Visual C#要透過dotnet40才能執行!而群益的範例程式`SKCOMTester.exe`正是用Visual C#寫成的! - 不需要裝2.0、3.0、4.5,.NET Framework也是一樣,DLL提供的API是很精確的!程式要call 4.0的DLL就是只能用4.0的DLL! ``` $ winetricks vcrun2010 vcrun2015 dotnet40 ``` 或是在ssh底下執行: ``` $ apt install xvfb $ time xvfb-run winetricks -q vcrun2010 vcrun2015 dotnet40 #靜態安裝,不會秀UI,目前只試過幾次,看起來是有效的!不過還是要再看實測穩定性! ``` - 下載群益API官網的`C#範例`,下載到`CapitalAPI_2.13.16_CExample.zip`、放它到Ubuntu 32bit的環境裡並且解壓縮它! - 進入資料夾`CapitalAPI_2.13.16_CExample`-->`元件`-->`x86` (建議把`元件`改名成`Components`,用英文比較好!) - 執行以下指令以註冊群益API所需要的DLL檔`SKCOM.dll`: ``` $ regsvr32 ./SKCOM.dll ``` - 實測發現,使用群益C# API寫的程式,時常會被Wine說會有`Make sure that ntlm_auth >= 3.0.25`的問題!要解決這個問題,需要安裝`winbind`這個套件: ``` $ sudo apt install winbind ``` - 接下來我們要自己下載根憑證檔`root certificate`並且自己透過IE5來安裝,以避免Wine內建的winhttp的HTTPS憑證的bug! ``` $ cd $ wget http://sslserver.twca.com.tw/cacert/root4096.crt $ wine control ``` - 接下來選擇`網際網路設定`-->`內容`-->`憑證...`-->選擇分頁`信賴的根憑證授權者`-->`匯入(I)...`,接下來選擇`root4096.crt`這個檔,然後一直按`下一步`,然後最後按`完成`!此時你應該要看到以下的畫面: ![](https://live.staticflickr.com/65535/48231022201_681f06aeaf_o.jpg) - 最近實測發現,實際上是Linux系統如果有安裝`root4096.crt`的話,Wine的環境似乎就可以不用透過IE5安裝`root4096.crt`!執行以下指令來在Linux系統裡安裝`root4096.crt`:(不過還是要實測一下穩定性!) ``` $ sudo cp -v ./root4096.crt /usr/local/share/ca-certificates/ $ sudo update-ca-certificates ``` - 最後我們可以來執行群益API的範例程式`SKCOMTester.exe`了! ``` $ cd ~/Capital/Components/x86 $ wine ./SKCOMTester.exe ``` - 再來登入自己的帳號密碼,先看看能不能登入! - 若出現`SK_ERROR_INITIALIZE_FAIL`的訊息,則代表剛剛`root4096.crt`沒有匯入到正確的分頁裡!Wine的HTTPS的bug還沒有繞掉! - 若出現`登入成功`的訊息,則代表真的登入成功了! ------ # 尚在研究的東西 - ~~目前在X Window之下透過「網際網路設定」手動匯入`root4096.crt`之後,群益API就可以動了!但是目前還需要在X Window的環境下執行!我猜測是在ssh之下沒有X Window,所以IE5已匯入`root4096.crt`的事實也一起被忽略了,所以又繞回使用`wininet`失敗的窘境。可以的話,我希望能不使用X Window也能讓它吃到`root4096.crt`根憑證檔!(不過我還沒trace這個case的WINEDEBUG log)~~ - 以上說的我事後追並不是因為沒有X Window而導致IE5已匯入`root4096.crt`的事實也一起被忽略,而是我寫的`skcom_test1.exe`雖然不是使用Visual C#寫的,但是它還是需要使用 .NET Framework 4.0的DLL檔,而且那個DLL檔似乎還一定要在X Window的環境下才不會有錯誤!這才是`skcom_test1.exe`在沒有X Window的SSH環境下不能執行的原因! - 目前我懶得解決這個問題了!我打算先使用Fake X Window來讓SSH的環境下也能執行`skcom_test1.exe`!而非常幸運的,我找到了`Xvfb`!(virtual framebuffer X server for X Version 11) - Ubuntu下安裝`Xvfb`的方法很簡單: ``` $ apt install xvfb ``` - 使用`Xvfb`的方法也很簡單!請參考[這一篇](http://elementalselenium.com/tips/38-headless)!以我的case來講: ``` $ xvfb-run wine ./skcom_test1.exe ``` - 如果是有二隻程式需要在同一個`Xvfb`所建立出來的`$DISPLAY`下執行的話,建議還是用Option 1中提到的`export`的方法!(Option 1的變形請參考[這一篇](https://blog.csdn.net/Nobody_Wang/article/details/60887659)!) - 目前已知道CA交易憑證一樣也是放匯入`root4096.crt`的那個視窗內!所以也許在X Window的環境之下,並不太需要擔心CA交易憑證匯入的問題! - 目前我的Ubuntu機的時區在安裝後都是正確的`Asia/Taipei`,但是LXC VM的時區在安裝後都是錯誤的`Etc/UTC`!Ubuntu機和LXC VM的時區是允許不同的!(神奇) 而要修改時區的話請參考[這一篇文章](https://www.opencli.com/linux/ubuntu-16-04-change-timezone-setting)!快速的修改方法和查詢方法是: ``` $ sudo timedatectl set-timezone Asia/Taipei #時區改為Asia/Taipei $ timedatectl #查詢目前時區 Local time: 三 2019-07-10 02:30:21 CST Universal time: 二 2019-07-09 18:30:21 UTC RTC time: 二 2019-07-09 18:30:21 Time zone: Asia/Taipei (CST, +0800) Network time on: yes NTP synchronized: yes RTC in local TZ: no ```

Import from clipboard

Paste your markdown or webpage here...

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lose their connection.

Create a note from template

Create a note from template

Oops...
This template has been removed or transferred.
Upgrade
All
  • All
  • Team
No template.

Create a template

Upgrade

Delete template

Do you really want to delete this template?
Turn this template into a regular note and keep its content, versions, and comments.

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Help & Tutorial

How to use Book mode

Slide Example

API Docs

Edit in VSCode

Install browser extension

Contacts

Feedback

Discord

Send us email

Resources

Releases

Pricing

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions and GitHub Sync
Get Full History Access

  • Edit version name
  • Delete

revision author avatar     named on  

More Less

Note content is identical to the latest version.
Compare
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

Feedback

Submission failed, please try again

Thanks for your support.

On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

Please give us some advice and help us improve HackMD.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully