Browsed by
Category: Java

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

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

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

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

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

Read More Read More

Facebooktwittergoogle_plusredditpinterestlinkedinmail
How to find the longest possible quasi-constant subsequence of array?

How to find the longest possible quasi-constant subsequence of array?

This is my task2 challenge. I’ve tried to solve this question, but my result wasn’t good. Although there was no error after testing, I only got 33% score.😰

The summary of question shows as below:

I was given a non-empty unsorted array such as: A = [6, 10, 6, 9, 7, 8]. The amplitude of a subsequence of array A is the difference between the largest and the smallest element in this subsequence. The amplitude of the empty subsequence is assumed to be 0.

These are some of the subsequences of array A and their amplitudes:
[6, 6, 7] has amplitude 1;
[6, 10, 6, 9, 7, 8] has amplitude 4;
[6, 6, 7, 8] has amplitude 2.

If this subsequence of array is called quasi-constant, it means its amplitude does not exceed 1. In the example above, subsequence [6, 6, 7] is the longest possible quasi-constant subsequence of array A.

Now, you are expected to provide a method that takes in an array and returns the maximum number of quasi-constant subsequence of array. In above example, the function should return 3.

Read More Read More

Facebooktwittergoogle_plusredditpinterestlinkedinmail
My first Codility test experience

My first Codility test experience

Last week, I received an email from a recruiter who asked me to do Codility assessment. I had to answer three questions within 245 minutes. Although I’ve heard about Codility, this was my first Codility test experience. To be honest, it was really difficult to me.

These questions were not easy to understand, so it took me some time to understand each question. Then I tried to answer the questions by Java or Python programming language. Even though I eventually found the solutions and summited the answers, my average score was not good enough. When I finished this assessment, I was very disappointed about myself. I even thought whether I should keep a programmer job.😂😂😂

It seems that more and more companies like to use Codility assessments to evaluate developers, but I don’t think it is a best way to test a programmer’s coding/programmer abilities.

Read More Read More

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

[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.

Read More Read More

Facebooktwittergoogle_plusredditpinterestlinkedinmail
[Java] Install/uninstall Oracle/Open JDK, Maven, Ant, Tomcat on Ubuntu14.04

[Java] Install/uninstall Oracle/Open JDK, Maven, Ant, Tomcat on Ubuntu14.04

I used the following command to install Java tools on Ubuntu14.04 , and it also works for old Ubuntu version.

Install Oracle JDK6, JDK7, JDK8

$ sudo apt-get install python-software-properties
$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get install oracle-java6-installer

or

$ sudo apt-get install oracle-java7-installer

or 

$ sudo apt-get install oracle-java8-installer

Read More Read More

Facebooktwittergoogle_plusredditpinterestlinkedinmail
[Java] Create a Simple Report by Jaspersoft Studio 6.1

[Java] Create a Simple Report by Jaspersoft Studio 6.1

Jaspersoft Studio is an Eclipse-based report designer for JasperReports Library and JasperReports Server; it’s available as an Eclipse plug-in or as a stand-alone application. Jaspersoft Studio allows you to create sophisticated layouts containing charts, images, subreports, crosstabs, and more. You can access your data through a variety of sources including JDBC, TableModels, JavaBeans, XML, Hibernate, Big Data (such as Hive), CSV, XML/A, as well as custom sources, then publish your reports as PDF, RTF, XML, XLS, CSV, HTML, XHTML, text, DOCX, or OpenOffice. But my focus is on how to create a simple report and simple code.

Read More Read More

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

[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)
]

Read More Read More

Facebooktwittergoogle_plusredditpinterestlinkedinmail