[Java] 支付寶(alipay) 境內支付API介接與實作

最近因為公司業務拓展需求,需要將公司的平台導入支付寶(alipay)的API,讓買家可以直接使用支付寶付款。原本以為這是一個很簡單的任務,沒想到因為對支付寶API的不熟悉,來來回回折騰了將近兩週才將支付功能開發完成。

支付寶的支付接口分為境內支付以及國際支付兩種。所謂的境內支付指的是買家用人民幣付款,賣家用人民幣取款。而國際支付則是買家用人民幣付款,賣家可以用指定幣種取款。因為我的公司是紐西蘭公司,當然就是用紐幣取款了。

這兩種支付接口所使用的API以及傳入的參數是完全不一樣的,但因為一開始不知道兩種支付方式使用不同的API,一直在螞蟻金服開放平台上的官方文件糾結了很久。且網路上的資訊新舊交雜,導致程式都寫完了才發現螞蟻金服開放平台上演示的API只能用於境內支付。恍然大悟之後改去用國際支付的API,程式重新撰寫配置才將此支付功能完成。

閱讀更多[Java] 支付寶(alipay) 境內支付API介接與實作

(Visited 3,242 times, 1 visits today)

[Java] How to use SSL and Google Protobuf on Netty?

Recently, I tried to use Netty framework dealing with message transferring between different virtual machines which are including one server and some clients. Meanwhile, I need to use SSL mutual authentication and Google protobuf when these VMs do communication cross the internet. Although I had already encountered the term “SSL” a lot of times, I soon realised that I had never fully understood how it really works and how it could be implemented in Java.

I would like to share my experience about implementing SSL plus Google Protobuf on Netty. But I wouldn’t exactly tell you what Netty, SSL and Google protobuf are.

閱讀更多[Java] How to use SSL and Google Protobuf on Netty?

(Visited 1,029 times, 1 visits today)

[Java] Using Jackson and Jersey to parse a JSON file to an List

This example will show you how to convert a JSON file into a JSON String, then parse it to ArrayList. Assuming I hava a timeZoneList.json file:

[
  {
    "zoneID": "Pacific/Kwajalein",
    "offset": -12,
    "zoneName": "(GMT -12:00) Eniwetok, Kwajalein"
  },
  {
    "zoneID": "Pacific/Midway",
    "offset": -11,
    "zoneName": "(GMT -11:00) Midway Island, Samoa"
  },
  {
    "zoneID": "US/Hawaii",
    "offset": -10,
    "zoneName": "(GMT -10:00) Hawaii"
  },
  .....(more timezone objects)
]

閱讀更多[Java] Using Jackson and Jersey to parse a JSON file to an List

(Visited 118 times, 1 visits today)

[Java] Converting between Decimal and Binary with Recursion

I am trying to write a program that will convert a binary number into its equivalent decimal number using recursion. Recursion has always been a confusing topic in programming. I write a simple code to implement convert from decimal to binary and from binary to decimal.

閱讀更多[Java] Converting between Decimal and Binary with Recursion

(Visited 25 times, 1 visits today)

[Java] Quick Sort Algorithm

Quick sort is a very fast sort algorithm, which it’s used “divide and conquer strategy” to sort the data. On the average and best case, it has O(n log n) time complexity, on worst case, it has O(n^2) time complexity. And it is unstable sorting.

閱讀更多[Java] Quick Sort Algorithm

(Visited 14 times, 1 visits today)

[Java] Selection Sort Algorithm

Time complexity of Selection Sort Algorithm in best case , worst case and average are all O(n^2) and need O(1) extra space. Selection sort can be implemented in stable sort or not.

閱讀更多[Java] Selection Sort Algorithm

(Visited 22 times, 1 visits today)

[Java] 100 – The 3n + 1 problem

題目連結:UVa Online Judge

本來中間的if/else判斷是用

if(n%2 == 1)
    int number = (3 * n) + 1;
else
    n = n/2;

閱讀更多[Java] 100 – The 3n + 1 problem

(Visited 22 times, 1 visits today)

[Java] Binary search algorithm

Binary search algorithm time complexity is O(log2(n)), and this algorithm requires that source array is sorted in order to work correct.

Algorithm is quite simple. It can be done either recursively or iteratively:

1.get the middle element;
2.if the middle element equals to the searched value, the algorithm stops;
3.otherwise, two cases are possible:
   (1)searched value is less, than the middle element. In this case, go to the step 1 for the part of the array, before middle element.
   (2)searched value is greater, than the middle element. In this case, go to the step 1 for the part of the array, after middle element.

閱讀更多[Java] Binary search algorithm

(Visited 25 times, 1 visits today)