Quick Sell API Development steps

Source: Internet
Author: User

Key field Description

1, Appkey and Appsecret

Appkey is the app's unique identity, Appsecret is the app's key, which is equivalent to the user name and password. After registering the app, a appkey and Appsecret will be generated, please save it properly.

2. Code

That is, the temporary token. When users access the app on an open platform, they need to authorize the app to access the user's privacy data after the user authorizes it. After completing the authorization, the user jumps to the Redirect_uri and takes the temporary token Code,app and then the code from the Open platform backend interface in exchange for Access_token. Code is a one-time token and is valid for 2 minutes.

3, Accesstoken

A user authorization token, which is an authorized identifier for a user session for a period of 10 hours. After obtaining code, get Accesstoken by calling the open platform background interface GetToken. When accessing user's privacy data, the app needs to bring Accesstoken, and only Accesstoken can be used as credentials for access, and other tokens such as code and Refreshtoken cannot be used as access credentials directly. You need to convert to Accesstoken before you can access user privacy data.

4, Refreshtoken

That is, the long season card, effective period six months. When Access_token expires, you can use Refreshtoken in exchange for new Accesstoken access to user data.

5, Redirect_uri is the callback address, refers to the application to initiate the request, the callback address parameters transmitted, must be filled. Please refer to the instructions in the authorization process. API Reference Description Address: Http://gw.api.alibaba.com/dev/doc/sys_auth.htm?ns=aliexpress.open-Speed selling API website address

Development Logic Flow

Hand Party welfare

Although the code is very messy, but feel very right to reach the party, haha!!!

/*
* Get information templates
*/
public static function Getaccounttemplates ($config)
{
$config [' modulestatus '] = ' approved ';
$config [' pageIndex '] = 1;
$apiname = "Api.findaeproductdetailmodulelistbyqurey";
Get information templates
$accountTemplats = Apiservice::getinfo ($config, $apiname);
return $accountTemplats;
}


/*
* Get Account Appkey
*/
public static function Getacountinfo ($account)
{
$account = Db::select (' Appkey ', ' account ', ' Appsecret ')
->from (' account ')
->where (' account ', ' = ', $account)
->execute (' system ')
->current ();
return $account;
}

New ways to get passes
public static function Newupdatetoken ($account)
{
$row = apiservice::newgetaccounts ($account [' account ']);
if ((Strtotime ($row [' access_create_time ']) +10*3600-60*10) <time ()) {
$ali = new Getapi ();
$accessToken = $ali->getaccesstoken ($row [' Refresh_token '], $account [' Appkey '], $account [' Appsecret ']); In exchange for Accesstoken through Refreshtoken.
if (Isset ($accessToken [' Error ')]) {
return $accessToken;
}
$set = Array (
' Access_token ' = $accessToken [' Access_token '],
' Access_create_time ' = Date (' y-m-d h:i:s ', Time ()),
);

$sql = "UPDATE ' erp_aliexpress_accounts '
SET access_token= ' ". $accessToken [' Access_token ']." ', Access_create_time= ' ". Date (' y-m-d h:i:s ')." '
WHERE ' aliid ' = '. $accessToken [' aliid '];

Db::query (Database::insert, $sql)
->execute (' system ');

$row [' access_token '] = $accessToken [' Access_token '];
}elseif ((Strtotime ($row [' refresh_create_time ') +180*24*3600) <time ()) {
$row [' access_token '] = NULL;
}
return $row [' Access_token '];
}

/**
* Get quick sell new account
* Enter description here ...
* @param unknown_type $account
*/
public static function newgetaccounts ($account = ", $fields =")
{
if (empty ($account)) {
Return ' account is empty ';
}else{

$result = Db::select (' Access_token ', ' refresh_token ', ' access_create_time ', ' refresh_create_time ')
->from (' erp_aliexpress_accounts ')
->where (' aliexpress_account ', ' = ', $account)
->execute (' system ')
->current ();
}
return $result;
}

/*
* Get Account Appkey
*/
public static function Getacountinfo ($account)
{
$account = Db::select (' Appkey ', ' account ', ' Appsecret ')
->from (' account ')
->where (' account ', ' = ', $account)
->execute (' system ')
->current ();
return $account;
}

/*
* Common Methods
*/
public static function GetInfo ($config, $apiname)
{
$appkey = Apiservice::getacountinfo ($config [' account ']);
$config [' appkey '] = $appkey [' Appkey '];
Get information templates
$api = new Getapi ();
$result = $api:: API ($config, $apiname);
return $result;
}

Const URL = ' http://gw.api.alibaba.com/openapi/';
Const SITE = ' aliexpress ';

/*
* API Common Method
*/
Public Function API ($set, $apiname)
{
if (Empty ($set [' Access_token '])) {
return FALSE;
}
$api _url = ' param2/1/aliexpress.open/'. $apiname. ' /'. $set [' Appkey '];
$url = Getapi::url. $api _url;
$data = Http_build_query ($set);
$result = Getapi::sendrequestcurl ($url, $data);
return $result;
}

/**
* Send Request
* Enter description here ...
* @param unknown_type $url
* @param unknown_type $data
*/
protected static function Sendrequestcurl ($url, $data)
{

$ch = Curl_init ();
curl_setopt ($ch, Curlopt_url, $url);
curl_setopt ($ch, Curlopt_ssl_verifypeer,false);
curl_setopt ($ch, curlopt_ssl_verifyhost,0);
curl_setopt ($ch, curlopt_post,true);
curl_setopt ($ch, Curlopt_postfields, $data);
curl_setopt ($ch, curlopt_timeout,300);
curl_setopt ($ch, curlopt_returntransfer,1);
$response = curl_exec ($ch);
Curl_close ($ch);
$response = Json_decode ($response, TRUE);
return $response;
}

/*
* Refreshtoken in exchange for Accesstoken
* Enter description here ...
* @param unknown_type $refreshToken
*/
Public Function Getaccesstoken ($refreshtoken, $appkey, $appsecret)
{
$code _arr = Array (
' client_id ' = = $appkey,
' grant_type ' = ' refresh_token ',
' client_secret ' = > $appsecret,
' refresh_token ' = $refreshtoken,
);
$sign _str = ' param2/1/system.oauth2/refreshtoken/ 544880 ';
$code _sign = getapi::apisign ($appsecret, $code _arr, $sign _str, $appsecret);
$getTokenUrl = ' https://gw.api.alibaba.com/openapi/param2/1/system.oauth2/refreshToken/'. $appkey;
$data = ' grant_type=refresh_token&refresh_token= '. $refreshtoken. ' &client_id= '. $appkey. ' &client_secret= '. $appsecret. ' &_aop_signature= '. $code _sign;
$result = $this->sendrequestcurl ($GETTOKENURL, $data);
return $result;
}


/**
* Signature String Group rules
* Enter description here ...
* @param unknown_type $REDIRECTURL
*/
protected static function Apisign ($appsecret, $code _arr, $sign _str = ")
{
Ksort ($code _arr);
foreach ($code _arr as $key = + $val) {
$sign _str. = $key. $val;
}
$code _sign = Strtoupper (Bin2Hex (Hash_hmac ("SHA1", $sign _str, $appsecret, TRUE)));
return $code _sign;
}

Quick Sell API Development steps

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.