Jump to: navigation, search

Order payment notification

Revision as of 14:56, 22 October 2014 by Huangyanli (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Order payment notification

Order payment flowchart


1.Game client calls AnySDK Framework payment API (payForProduct), AnySDK Framework will request AnySDK server to generate an order number.
2.AnySDK Framework obtains the order number generated by the server.
3.AnySDK Framework calls SDK payment api to request payment from SDK server.
4.After payment is successful, payment SDK will return payment successful message to AnySDK Framework, and the AnySDK Framework will then carry out payment successful callback function to notify game client.
Note: When the SDK returns the successful callback, it only indicates that the transaction has been successfully submitted to SDK server, it does not mean that the order has been successfully paid. For some payment SDKs user only needs to enter payment selection screen, and the SDK will generate an order and return with a payment successful callback even if user cancels payment or payment fails. That is why the payment result only depends on whether game server has received SDK server payment callback information and not rely on local payment callback.

5.After SDK server completes payment, it will send order verification information and notify AnySDK server asynchronously.
Note: This step requires developers to configure the back-end payment callback address as the payment callback address dedicated to each channel provided by AnySDK (i.e. the screen where developer obtains SDK parameters). This address can be checked at the package tool parameters configuration screen.
6.AnySDK server will check the order information send by the SDK server and return with a correct response.
7.AnySDK will send the payment result information to the payment callback address provided by the game server. This address is on the package tool parameters configuration screen.
8、The game server will check the information send by AnySDK. It does not matter whether it checks a valid order of an item to be granted or an invalid order that needs to be discarded, as long as the game server completes this notification process, be sure to return with the correct response ok or OK, or else AnySDK will duplicate the notification and put pressure on the game server.
9.Game server verifies payment notification and provides item.

Notify game server

After payment, AnySDK payment notification service will inform developers the payment result by the payment notification address (callback address). After receiving and test the params, developer server will recharge the user account or distribute the props.

Coding instruction

UTF-8 code should be used during the transport process.

Parameter specification

Param Param type Specification
order_id string Order id, produced by AnySDK
product_count string Product quantity (the exact quantity cannot be provided now)
amount string Payment amount. Unit is yuan. Value can be floating points based on the requirement of different channels
pay_status string Payment status. 1 is success.
pay_time string Payment time. Form: YYYY-mm-dd HH:ii:ss
user_id string User id in custom system
order_type string Order type. See details in payment channel list
game_user_id string User id in the game. Role_Id params that are imported while paying.
server_id string Server id. Server_id params that are imported while paying.
product_name string Product name. Product name params that are imported while paying
product_id string Product id. Product id params that are imported while paying.
private_data string Private data, ext params that imported while calling client payment function, and will be passed to game server.
channel_number string Channel Number
sign string Sign. To check the sign, refer to signature algorithm.
source string Requested parameters when SDK server notifies AnySDK

Game server responses

The app should respond ok (character string, not json form) after receiving the notification to confirm the reception. If it responds other value or nothing, the notification is thought to be a failure and AnySDK payment notification server will try more times.

Signature algorithm

1. All non-empty parameters are listed in ascending alphabetical order, sign parameters are not included in signature.
2. Use numerical string method to put the listed parameters together in order.
3. Do an one-time md5 and convert to lower case, obtain encrypted string 1.
4. When following the encrypted string 1 up with private_key at the end, do an one-time md5 encryption and convert into lower case, the string obtained is the signature “sign” value.
3. When comparing obtained signature value with parameter “sign”, if they are the same then verification will be succesful.
Note: If values are included in signature, then parameters cannot be included in signature.

For example if received data is: a=3&c=1&b=2    string=321 【here is no + in actual string, + is only a connected string】


php check example:

 * payment notification check demo

$data = $_POST;
* Please note that with regard to $_POST data if the server does not automatically process urldecode, do an one-time urldecode (refer to rfc1738 standards). 
foreach ($data as $key => $value) {
        $data[$key] = urldecode($value);

$privateKey = "abcdef123456xxxxxx";
if (checkSign($data, $privateKey)) {
        // @todo If verification is successful, the game server will process logic
        echo "ok";
} else {
        echo "failed";

 * @param array $data receives all requested parameter arrays, can be obtained through $_POST. Please note that if server does not automatically analyze data, do an one-time urldecode( refer to rfc1738 standards)

 * @param array $privateKey AnySDK allocates game privateKey 
 * @return bool
function checkSign($data, $privateKey) {
        if (empty($data) || !isset($data['sign']) || empty($privateKey)) {
                return false;
        $sign = $data['sign'];
        $_sign = getSign($data, $privateKey);
        if ($_sign != $sign) {
                return false;
        return true;

 * Compute signature
 * @param array $data
 * @param string $privateKey
 * @return string
function getSign($data, $privateKey) {
        //sign Does not participate in signature
        //Array listed in key ascending order
        // The values in array is without any partition    
combined into a string
        $string = implode('', $data);
        //Create an one time md5 and convert to lower case, add the game’s privateKey at the end, finally create another md5 and convert to lower case
        return strtolower(md5(strtolower(md5($string)) . $privateKey));


More demo checks

 anysdk-pay-notice-java-demo1.zip   (Provided by Quanzhou Zhufeng software)
 anysdk-pay-notice-java-demo2.zip   (Provided by Beijing Zhidian Qiankun)

Online check

Online API check

1. First install Chrome’s extension POSTMAN or install Firefox plug-in HttpRequester (used to simulate API requests)
2. URL:inner.anysdk.com/tools/check/sign
3. Content Type: x-www-form-urlencoded
4. Select POST method
5. The param value of the parameter is the paratemer character string after callback address (meaning that after the question mark) of notification parameter under AnySDK Developer Management Backend => Payment Management => Payment Notification Details => Game Server Notification Details.
6. Private_key value is the private_key provided to a game by AnySDK
7.Example picture:

Chrome browser POSTMAN extensions uses:



Notification duplication

The server of content provider should be ready to receive multiple notification to prevent multiple additional payments.
At the same time developer should keep in mind that, an “ok” response indicates that the app has properly received the information. There is no need to continue sending a notification, it will not show whether the payment or process is successful or not.
With regard to duplicate notifications, the user may find that the order has been successfully processed. There is no need to continue processing, just go back with “ok” (lower case strings). Otherwise the AnySDK payment notification service will consider the notification to be unsuccessful and will continue sending notifications.
The notifications will be repeated at the following intervals: 2 min., 10 min., 10.min, 1 hour, 2 hours, 6 hours, 15 hours (a total of 7 times), and it will end until it receives a successful feedback or it has finished sending 7 times.