Alipay: Instant to account interface Docking _ Alipay

Source: Internet
Author: User
Payment Treasure Interface Demo document download

https://doc.open.alipay.com/doc2/detail.htm?spm=a219a.7629140.0.0.qAEbso&treeId=62&articleId=103566 &doctype=1 Create feedback table payment business logic processing

1, the payment interface of "partner ID" and "key" to apply for their own, here skipped

After downloading the demo document, choose the language and coding format for your project, which is Java-utf-8
Then import into your project (the directory structure itself is free to compose, I use the format provided by the document)

Then go to the alipayconfig to fill in the requested partner ID and key.

2, the Alipayparams of feedback information table
(The table is also not created, primarily to be able to record information about each transaction's information recording details)
Refer to the document contents of the instant to account transaction interface-"Server asynchronous notification parameter description"
Create a Alipayparams table

DROP TABLE IF EXISTS m_alipayparams; CREATE TABLE m_alipayparams (payid int UNSIGNED not NULL auto_increment PRIMARY KEY, PayType Int (one) DEFAULT 0 comme NT ' Order: 0-paid, 1-refund, 2-present, 3-top-up ', sign VARCHAR (MB) default null COMMENT ' signature ', Sign_type VARCHAR ($) default NULL COMM  ENT ' signature method ', Paymethod VARCHAR (MB) default null COMMENT ' payment method: DirectPay (Balance Payment) ', notify_id VARCHAR (MB) default null COMMENT ' notification checksum ID ', notify_type VARCHAR default NULL COMMENT ' notification type dsa/rsa/md5 ', Notify_time DATETIME DEFAULT NU LL COMMENT ' notification time ', Trade_no VARCHAR (MB) default null COMMENT ' Alipay transaction number ', Out_trade_no VARCHAR (MB) default NULL comme NT ' Merchant website unique order number ', subject VARCHAR (257) default null COMMENT ' commodity name ', Payment_type VARCHAR (one) default null COMMENT ' Payment class 
   Type 1: Commodity purchase ', Trade_status VARCHAR (MB) default null COMMENT ' transaction status ', gmt_create DATETIME default null COMMENT ' Transaction creation time ', gmt_payment datetime default NULL COMMENT ' Transaction payment time ', Gmt_close datetime default NULL COMMENT ' Transaction shutdown time', gmt_refund DATETIME default null COMMENT ' Refund time ', Refund_status VARCHAR ($) default null COMMENT ' refund status ', Selle R_ID VARCHAR default null COMMENT ' seller Alipay user number ', Seller_email VARCHAR (MB) default null COMMENT ' seller Alipay account ', Buyer_ ID VARCHAR default NULL COMMENT ' buyer Alipay user number ', Buyer_email VARCHAR (MB) default null COMMENT ' buyer Alipay account ', Price DOU 
   BLE default 0 COMMENT ' Commodity unit price ', Priceunit INT (one) default 0 COMMENT ' unit ', Quantity INT (one) default 0 COMMENT ' purchase quantity ', Total_fee DOUBLE default 0 COMMENT ' transaction amount ', Body VARCHAR (MB) default NULL COMMENT ' Description of product ', Discount VARCHAR (100) Default null COMMENT ' discount ', Is_total_fee_adjust VARCHAR (a) default null COMMENT ' adjust Total price ', Use_coupon VARCHAR (a) DEF Ault null COMMENT ' whether to use a red envelope buyer ', Extra_common_param VARCHAR (MB) DEFAULT NULL COMMENT ' common return parameters ', Business_scene varcha R (MB) default NULL COMMENT ' whether to sweep the code to pay ', createtime DATETIME COMMENT ' creation time ') Engine=myisam default Charset=utf8 comment= ' branch
 Bao Information record table ';

Next step in the consolidation implementation
in the download Alipay demo document, you can see that alipayapi.jsp and notify_url.jsp

Translate the code from these two pages into Java writing Alipayaction.ja VA

    /** * Alipay Server Asynchronous Notification page * @param req * @param RES/@RequestMapping (value= "/alipaynotify") pu Blic void Alipaynotify (HttpServletRequest req,httpservletresponse res) {//Get Alipay post over feedback map<string,st
        ring> params = new hashmap<string,string> ();
        Map requestparams = Request.getparametermap (); for (Iterator iter = Requestparams.keyset (). iterator (); Iter.hasnext ();)
            {String name = (string) iter.next ();
            String[] values = (string[]) requestparams.get (name);
            String valuestr = "";
                        for (int i = 0; i < values.length i++) {valuestr = (i = = values.length-1)? valuestr + Values[i]
            : Valuestr + values[i] + ","; //garbled solution, this code in the occurrence of garbled use.
            If MySign and sign are not equal, you can also use this code to convert//VALUESTR = new String (valuestr.getbytes ("iso-8859-1"), "GBK");
        Params.put (name, VALUESTR); //Get Alipay notification return parameters, reference technologyPage jump sync notification parameter list in document (for reference only)///** Merchant Order number///string out_trade_no = new String (Request.getparameter ("Out_trade_n

        O "). GetBytes (" Iso-8859-1 ")," UTF-8 ");

        /** Alipay Trading Number *///string trade_no = new String (Request.getparameter ("Trade_no"). GetBytes ("Iso-8859-1"), "UTF-8");
        /** Trading Status */String Trade_status = "";
        try {trade_status = new String (Request.getparameter ("Trade_status"). GetBytes ("Iso-8859-1"), "UTF-8");
        catch (Unsupportedencodingexception e) {e.printstacktrace (); //Get Alipay notification return parameters, refer to Technical Documents page Jump sync notification parameter list (above for reference only)/if (alipaynotify.verify (params)) {//Verify success///// ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓//////////Please add the Merchant's business Logic program code//--please write the program according to your business logic (the following code is for reference only)-
                -/** * Trade_finished (indicates that the transaction has been successfully concluded and no further action can be taken on the transaction);
             Trade_success (indicates that the transaction has been successfully completed, you can follow up on the transaction, such as: splitting, refund, etc.); */if (trade_status.equals) ("Trade_finishED ")" {//determine if the order has been processed on the merchant website///If no processing has been done, find out the order details in the order system of the merchant's website according to the order number (OUT_TRADE_NO) and execute the merchant Business Procedures//Please be sure to judge the request when the Total_fee, SELLER_ID and notification of the Total_fee, seller_id for the same//if there has been handled, do not execute the merchant Business process//NOTE://Refund date beyond the refundable period (such as three month refund), Alipay system sends the transaction status notice} else if (Trade_status.eq Uals ("trade_success")) {//Determine if the order has been processed on the merchant website//If no processing has been done, order number (OUT_TRADE_NO) on the merchant website
                    The details of this order are found in the EC, and the business procedures of the merchant are executed//Please be sure to judge the Total_fee, seller_id and Total_fee at the time of the request, seller_id as the same as If there is done processing, do not execute merchant business procedure//NOTE://payment is completed, Alipay system sends the transaction status notice}//--please according to your industry Business logic to write the program (the above code is for reference only)--out ("Success", RES); Do not modify or delete/////↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑/////}else{//validation failed out ("fail
        ", RES); /** * Send request to Alipay * @param req * @param res *@param alipayconfig */@RequestMapping (value= "/alipayapi") public void Alipayapi (HttpServletRequest Req,https

        Ervletresponse res,alipayconfig alipayconfig) {/** Merchant order number, the unique order number in the order system of the Merchant website, must fill/String out_trade_no = "";

        /** order name, must fill/String subject = "";

        /** payment amount, must fill/String Total_fee = "";
        /** Product Description, can be empty/String BODY = "";
            try {out_trade_no = new String (Request.getparameter ("Widout_trade_no"). GetBytes ("Iso-8859-1"), "UTF-8");
            Subject = new String (Request.getparameter ("Widsubject"). GetBytes ("Iso-8859-1"), "UTF-8");
            Total_fee = new String (Request.getparameter ("Widtotal_fee"). GetBytes ("Iso-8859-1"), "UTF-8");
        BODY = new String (Request.getparameter ("Widbody"). GetBytes ("Iso-8859-1"), "UTF-8");
        catch (Unsupportedencodingexception e) {e.printstacktrace (); }

        ///////////////////////////////////////////////////////////////////////////////** the request parameters are packaged in a group/map<string, string> sparatemp = new hashmap<string, string> ();
        Sparatemp.put ("service", alipayconfig.service);//Sparatemp.put ("partner", Alipayconfig.partner);
        Sparatemp.put ("seller_id", alipayconfig.seller_id); Sparatemp.put ("_input_charset", alipayconfig.input_charset);//Sparatemp.put ("Payment_type", AlipayConfig.payment
        _TYPE);//Sparatemp.put ("Notify_url", Alipayconfig.notify_url);
        Sparatemp.put ("Return_url", Alipayconfig.return_url); Sparatemp.put ("Anti_phishing_key", alipayconfig.anti_phishing_key);//Sparatemp.put ("Exter_invoke_ip", AlipayConf
        IG.EXTER_INVOKE_IP);//Sparatemp.put ("Out_trade_no", out_trade_no);
        Sparatemp.put ("Subject", subject);
        Sparatemp.put ("Total_fee", Total_fee);
        Sparatemp.put ("Body", the body); Additional business parameters Add parameters according to the online development documentation. Document Address: Https://doc.open.alipay.com/doc2/detail.htm?spm=a219a.7629140.0.0.O9yorI&treeId=62&articleid=103740&doctype=1//such as Sparatemp.put ("parameter name", "parametric value");
        /** Create request/String Shtmltext = Alipaysubmit.buildrequest (sparatemp, "get", "confirm");
    Out (Shtmltext,res); }

Then write your own business logic within the Alipaynotify method ....

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.