Alipay interface program, Documentation and interpretation (asp.net) __net

Source: Internet
Author: User
Tags md5 md5 encryption

It programmer development must-all kinds of resources download list, the most complete IT resources in history, personal collection summary.
Recently, the need for the site to add Alipay to the recharge interface, and the current information on the development of Alipay interface is more cluttered, here on my development of the data used to collate, I hope to help the needs of friends.

Development steps: 1. Determine the type of contract

Alipay's interface has many types, so first you have to determine the type of contract signed, determine which interface to use, do not go wrong way.

In this step, you can refer to the documentation: Alipay interface Operations Tutorial 2. Download Development Documentation

If the development is instant to account, please download and read it carefully: Standard Fast payment Interface document

The documentation provides a more detailed description of the logical process, sequence diagram, and enumeration definitions, preferably read through 3 before you look at the sample code . Obtain the payment of signed account the whole school examination Code (key) and cooperation Id:partner

Alipay sample program debugging requires the merchant number and the corresponding key, otherwise unable to debug the program, the specific methods of access please check the official help, no longer repeat 4. Download Alipay Sample program

ASP instant to account Interface code instance: click here to download (31.62 KB)

PHP_GBK instant to account Interface code instance: click here to download (22.02 KB)

Php_utf-8 instant to account Interface code instance: click here to download (22.02 KB)

NET_05_GBK (post mode) instant to account Interface code instance: click here to download (12.03 KB)

Net_05_utf-8 (post mode) instant to account Interface code instance: click here to download (10.72 KB)

JAVA_GBK (Get Way) instant to account Interface code instance: click here to download (136.54 KB)

Java_utf-8 (Get Way) instant to account Interface Code instance: Click this download (112.67 KB) 5. An interpretation of the example program of Alipay

The following is transferred from http://dev.alipay.com/devclub/mvnforum/viewthread_thread,161_offset,0

Everybody must have this kind of confusion--get Alipay's interface code, although inside the program has the annotation, the interface code package also has the development explanation, but still does not know how to start. It's not hard to imagine why, because you don't know what the interface works.
Then this article is to show you all about Alipay interface, so that everyone can quickly get to the interface to access their projects, but also to help those who already know the Alipay interface of the program developers to know more about Alipay some of the general rules, special purposes and so on.

Start with the topic--

first, the structure
A generally consists of two parts, the access part and the notification return part. The access section is to synthesize the hyperlink for the information group such as pass parameter and use the link to jump. The notification return part is the Alipay server after processing the order, notify and return the Order details to merchant server, business
The user server receives the data and processes it.
b) in the Physical standard dual interface ASP code procedures for example.
I. The paging file for the Access section includes: Configure page alipay_config.asp, method detail Page alipay/alipay_payto.asp, program entry page index.asp, and MD5 encryption method class page Alipayto/alipay_ Md5.asp.
Ii. the paging file for the Notification return section contains: Method detail Page alipay/alipay_payto.asp, MD5 Encryption Method class page alipayto/alipay_md5.asp, After payment is completed (after Alipay processing) automatically jump back to the custom page return_alipay_notify.asp, the two-party server interaction (The naked eye can not see) notice page alipay_notif
Y.asp.
Here you can at a glance, MD5 encryption method class and method detail page regardless of which part has been called, so these two files as the core code part, if you want to understand the work of the interface to start from this part.
(c) The ASP.net C # language code program, which is a standard dual interface, is an example:
I. The paging file for the Access section contains the AliPay class file App_code/alipay.cs and the entry page file that need not be changed default.aspx
Ii. the paging file for the return section of the notification contains: the alipay_notify.aspx of the two-party servers interacting with each other (not visible to the naked eye), and the custom page that automatically jumps back after the payment is completed (after Alipay processing) alipay_return.aspx,
AliPay class files that do not need to be changed App_code/alipay.cs
Whether the architecture is easier to understand. Yes, the core part of the operation is in AliPay.cs this file.

second, the principle of work
Now that we have some understanding of the structure, we begin to analyze how the specific interface works.
A) principle of access part
I. First step-select parameter information:
Combining technical documentation and interface code demo, select the parameters passed to the Alipay server, taking the physical standard dual interface as an example. If necessary, the service, partner, Seller_email, sign, Sign_type, Out_trade
_no, price, subject, quantity, Payment_type, and at least one set of logistics information parameters three Logistics_type, Logistics_fee, logistics_payment
And so on, the choice fills the body, discount, Show_url and so on.
Take the asp.net C # language code program as an example:
String service = "Trade_create_by_buyer";
String seller_email = "aaaa@126.com";
String sign_type = "MD5";
string key = "********************************";
String partner = "2088************";
String _input_charset = "Utf-8";
String show_url = "http://www.alipay.com/";
String out_trade_no = TxtOrderno.Text.Trim ();
String subject = TxtSubject.Text.Trim ();
String BODY = TxtBody.Text.Trim ();
String price = TxtPrice.Text.Trim ();
String quantity = TxtQua.Text.Trim ();
String logistics_type = "POST";
String logistics_fee = TxtPost.Text.Trim ();
String logistics_payment = "Buyer_pay";
String notify_url = "Http://www.xxx.com/swnet05utf8/Alipay_Notify.aspx";
String return_url = "Http://www.xxx.com/swnet05utf8/Alipay_Return.aspx";


Ii. Second Step-sort:
The variable names of these arguments (that is, the variable names given in the technical document are combined in this way: Service= "Trade_create_by_buyer" as a string of strings) sorted sequentially from A to Z. Take the asp.net C # language code program as an example, the feature is in the ALIPAY.CS class, and in the case of a program in ASP code, the feature is in the alipayto/alipay_payto.asp file.
Iii. Third Step-encryption:
The current general encryption method is MD5, regardless of the encryption method, the information to be encrypted is to be passed to the Alipay information, and exists in the technical documentation, rather than the custom variable name. All parameters that are sorted well above (excluding gateway parameters: string gateway = "Https://www.alipay.com/cooperate/gateway.do?";) in a circular manner, with ' & ' character concatenation into a long string of strings (note here, all the parameters are & character stitching, stitching directly and then stitching the security check code key, in the program you can see that the key is directly added to the string behind without using & characters), after encryption. The resulting set of cryptographic strings is stored in the sign parameter.
Iv. Step fourth-splicing strings into URL links
We've got the parameters, the values of the parameters, and the encrypted strings, so all the parameter information in the hand should be formatted as a set of service= "Trade_create_by_buyer" in this format, spliced, Then rely on loops to traverse all of this string, because this time the stitching is to be URL link, so before the exclusion of the gateway Gaetway and encryption type parameters sig
N_type will also be spliced in, then, the connected characters in the well-known characters ' & ', so that a complete URL link address, such as:
Https://www.alipay.com/cooperate/gateway.do?s...3d199ba&sign_type=MD5


This link comes from Alipay's official technical document "Standard physical dual Interface technical document"
V. Step fifth-Automatic jump
The fourth step has been the calculation of the URL link string, we have to let it live, then the way to live--call it with the program, which is called the page automatic jump. This will be able to jump to Alipay's official checkout page.
It can be said that now has successfully put the Alipay interface into everyone's own website, and can use to pay for the payment of Bora.
b) Notification return part principle
I. Professional terminology
Notification return is two pages, that is, when passed to Alipay notify_url parameters corresponding to the page file (asp.net is alipay_notify.aspx, ASP is alipay_notify.asp) called the notification page, passing
To pay treasure when the Return_url parameters of the page file (asp.net is alipay_return.aspx, ASP is return_alipay_notify.asp) called the return page.
Ii. principle of notification return
1. First step-Verify that the request is from the Alipay server:
(a) Take the ASP program code as an example:
Alipaynotifyurl = "Http://notify.alipay.com/trade/notify_query.do?"
Alipaynotifyurl = Alipaynotifyurl & "partner=" & Partner & "&notify_id=" & Request ("notify_id")
Set retrieval = Server.CreateObject ("msxml2.serverxmlhttp.3.0")
Retrieval.setoption 2, 13056
Retrieval.open "Get", Alipaynotifyurl, False, "", ""
Retrieval.send ()
Responsetxt = Retrieval.responsetext
Set retrieval = Nothing


What you get is the value of Responsetxt, which is what the following steps need to use.
b) Take asp.net C # program code as an example:
Get the remote server ATN results and verify that the request was sent from the Alipay server
public string Get_http (string a_strurl, int timeout)
{
String strresult;
Try
{
HttpWebRequest Myreq = (HttpWebRequest) httpwebrequest.create (A_strurl);
Myreq.timeout = Timeout;
HttpWebResponse Httpwresp = (HttpWebResponse) myreq.getresponse ();
Stream MyStream = Httpwresp.getresponsestream ();
StreamReader sr = new StreamReader (MyStream, Encoding.default);
StringBuilder Strbuilder = new StringBuilder ();
while ( -1!= Sr. Peek ())
{
Strbuilder.append (Sr. ReadLine ());
}

strresult = Strbuilder.tostring ();
}
catch (Exception exp)
{

strresult = "Error:" + exp. message;
}

return strresult;
}


Call section:
String Alipaynotifyurl = "

Related Article

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.