Azizo - Docking Taobao Third Party Platform

Customer Requirements: The order price of Taobao is automatically obtained when the system records the order. When the system operates the order is completed, the order is automatically delivered in Taobao.

I used Aziso here, which is a better third-party platform for docking Taobao. The development documents are simple and easy to understand, and the customer service apple is better.

Before entering development, we need to apply for our own account in Aziso Open Platform and authenticate some relevant information according to the platform requirements. Finally, create your own Appid (automatically generate the corresponding secret) and let the customer login to the Taobao authorized address. https://alds.agiso.com/Open/Authorize.aspx . After the authorization is completed, access Token can be obtained, and then it can be formally developed (Azizo also has his own development documentation, which is more clear, make a record by himself).

Take a look at your ideas.

1. A Taobao store corresponds to an AccessToken, and customers have more than one Taobao shop.

2. Need to use the functions, get Taobao order details, automatic push Wangwang message, automatic delivery function and so on.

Implementation steps:

The platform's Appid, secret and Taobao-authorized Access Token create corresponding fields in the database and save these data to the database, so that when different Taobao stores call Azizo's interface, they can obtain the corresponding Taobao-authorized Access Token.

Write a tool class of Azizo calling interface to satisfy a tool class calling different Azizo interfaces.

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;

import com.cdchengqitech.business.pojo.TaobaoInterfaceBPo;

public class AQiSuoUtil {
	/*inParm tid is the order number of Taobao and method is the interface url corresponding to Aziso.
         TaobaoInterfaceBPo The entity class is the access Token which stores the platform's appid and secret, and Taobao's authorization code.
         This modification satisfies many interfaces for a method call to Azizo
         */
	public static String temp(String inParam,String tid,String method,TaobaoInterfaceBPo tb){  
		String appSecret = tb.getAppSecret();//appSecret of Platform 
	    String accessToken = tb.getAccessToken();//Taobao Authorization Code
	    CloseableHttpClient httpclient = HttpClients.createDefault();
	    
	    HttpPost httpPost = new HttpPost(method);//Call interface
	    
	    //Setting Head
	    httpPost.addHeader("Authorization","Bearer "+ accessToken);
	    httpPost.addHeader("ApiVersion","1");
	    
	    //Business parameters
	    Map<String, String> data = new HashMap<String, String>();
	    data.put(inParam, tid);//InParam calls the parameters corresponding to the interface, and has a tips share. The inParam parameter in tid is
            //For a single order number, this value is tid. If the TID parameter is multi-parameter, inParam is tids.
//	    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	    Long timestamp = System.currentTimeMillis() / 1000;
	    data.put("timestamp", timestamp.toString());
	    //Parametric signature
	    try {
	        data.put("sign", Sign(data,appSecret));
	    } catch (NoSuchAlgorithmException e) {
	        e.printStackTrace();
	    } catch (UnsupportedEncodingException e) {
	        e.printStackTrace();
	    }
	    List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
	    for (Map.Entry<String, String> entry : data.entrySet()) {
	        params.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
	    }
	    //Launching POST requests
	    try {  
	        httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));  
	        HttpResponse httpResponse = httpclient.execute(httpPost);  
	        if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {  
	            return EntityUtils.toString(httpResponse.getEntity());  
	        } else {  
	            return ("doPost Error Response: " + httpResponse.getStatusLine().toString());  
	        }  
	    } catch (Exception e) {  
	        e.printStackTrace();
	        return null;
	    }  
	}
	//Parametric signature
	public static String Sign(Map<String, String> params,String appSecret) throws NoSuchAlgorithmException, UnsupportedEncodingException
	{  
	    String[] keys = params.keySet().toArray(new String[0]);
	    Arrays.sort(keys);
	    
	    StringBuilder query = new StringBuilder();
	    query.append(appSecret);
	    for (String key : keys) {
	        String value = params.get(key);
	        query.append(key).append(value);
	    }
	    query.append(appSecret);
	    
	    byte[] md5byte = encryptMD5(query.toString());
	    
	    return  byte2hex(md5byte);
	}
	//Converting byte arrays to hexadecimal strings
	public static String byte2hex(byte[] bytes) {
	    StringBuilder sign = new StringBuilder();
	    for (int i = 0; i < bytes.length; i++) {
	        String hex = Integer.toHexString(bytes[i] & 0xFF);
	        if (hex.length() == 1) {
	            sign.append("0");
	        }
	        sign.append(hex.toLowerCase());
	    }
	    return sign.toString();
	}
	//Md5 Summary
	public static byte[] encryptMD5(String data) throws NoSuchAlgorithmException, UnsupportedEncodingException {
	    MessageDigest md5 = MessageDigest.getInstance("MD5"); 
	    return md5.digest(data.getBytes("UTF-8")); 
	}


}

The return value of calling this method is introduced in the open platform, a class is written corresponding to the return value parameter, and then converted into an object using json.

import com.fasterxml.jackson.annotation.JsonInclude;

import lombok.Data;
import lombok.experimental.Accessors;

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
@Accessors(chain = true)
public class TaoBaoResp {
	private Boolean IsSuccess;
	private TaoBaoPo Data;

	public static Response success() {
		return new Response();
	}

	public static Response success(TaoBaoPo Data) {
		return new Response().setData(Data);
	}

	public static Response fail(String msg) {
		return new Response().setCode(-1).setMsg(msg);
	}
}

@Data
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
public class TaoBaoPo {

        //There are a lot of parameters, and I just take a part of what I need.
	private String BuyerNick;
	
	private BigDecimal Price; 
	
	private BigDecimal TotalFee; 
	
	private String ResultMsg;
	
	private Integer ResultCode;
	
	private String ErrorMsg;
	
	private Integer ErrorCode;
}



Finally, the Aziso interface can be invoked to obtain the order price and complete the automatic delivery function according to the actual demand.

 

 

 

 

 

 

 

 

 

 

Tags: Apache Java Database Lombok

Posted on Fri, 30 Aug 2019 00:27:20 -0700 by Code_guy