Golang docking Bao Fu, contacts, rich friends Gold account ... Pits Kee

Source: Internet
Author: User
Tags readfile

First, the treasure to pay the private key encryption, public key decryption

Because of the RSA encryption and decryption principle is not very familiar, Bao Fu also did not Golang demo offers. The Go language library is usually a private key decryption, public key encryption, or private key signature, public key verification. Bao Fu need in turn, here also to good find the implementation of HTTPS://GITHUB.COM/FARMERX/GORSA, but always treasure pay over there prompt signature verification failed. And then continue to find other implementations, which is the worst of all the various Google completely without solution. In the end, you can only use the decrypted source to compare the results with the. NET Platform. After a toss or torture, found that in fact, only a 117-byte encryption is all 0, the subsequent encryption results are similar to other platforms. As a result, the Armerxgorsa made the following changes, success.

It took 3 days before and after this. Although the solution to the problem is ultimately simple, the process of finding it is a great way out.

Second, the key analysis of communications

Alipay's key can be parsed directly using the Go Language pack, but the contacts are tricky. Given the P12 file is under Windows, continue with Bing. Fortunately, the result is very soon, and of course the largest gay exchange platform Https://github.com/ikaiguang/go-allinpay. Although the reference code is there, there are still problems. Let a friend Mac computer key conversion out of PEM file always parse failed, 1.2K, than can parse the larger.

This time I think of Win10 contains Linux subsystem, has been installed before, but not how to play. can just try it. Operation is still very Microsoft-productivity platform. 1.WIndows function enabled 2.win10 App Store search ubuntu, install. 3. Do something directly with the Linux subsystem!

Locate the path where you want to convert the key, and execute the following command.

  

OpenSSL pkcs12-nocerts-nodes-in2006040000049100420060400000491004-inform DER - in Allinpay-pdsdev.cer-out Allinpay-pdsdev.pem

Three, rich friends Gold account key

  There are these pits, basically flat almost after the addition and decryption of the payment platform is basically familiar with, and then the docking gold account is much easier. A simple try, key. Eventually the Java version can be used, except that the private key is parsed using PKCS1, and the public key is parsed using Pkixpublickey.

func init () {carfile, err:= Ioutil. ReadFile ("Assets/prkey.key")    ifErr! =Nil {return} Pemblock, _:=PEM. Decode (Carfile)ifPemblock = =Nil {return} Parsedkey, err:=X509. Parsepkcs1privatekey (pemblock.bytes)ifErr! =Nil {return} Jzhsignakey=Parsedkey Verify, err:= Ioutil. ReadFile ("Assets/pbkey.key")    ifErr! =Nil {return} block, _:=PEM. Decode (verify)ifblock = =Nil {return} pub, err:=X509. Parsepkixpublickey (block. Bytes)ifErr! =Nil {return} Jzhverfykey= Pub. (*RSA. PublicKey)}

Iv. getting sub-content in XML

  Basically add decryption after the trip, the other is a small problem. Be familiar with the basic library of Golang. The clear text required for the verification is intercepted from the XML returned by Fuyou, and it is a good encapsulation of big. Net. A method is good, at first also want to follow this routine to find Golang implementation, seemingly golang in the XML parsing, without the help of other third-party libraries, the main two kinds of 1. Parse to struct;2. Do not know the actual XML content is parsed by the XML basic attributes.

Finally, a regular expression is used to intercept.

var plaintxt=xmldoc.element ("plain")?. ToString (saveoptions.disableformatting)

Five, business interface docking

The rest of the main business interface is the implementation of the specific docking. The main examples are as follows: Completed the Gold account registration, Bao pay naked buckle, contacts quick buckle. Code Open source on the Https://github.com/KendoCross/KendoPay, the future intends to continue to improve and docking ePRO and other major payment platforms.

Package Kendopayimport ("FMT"    "Testing"    " Time")//Gold Account RegistrationFunc Testjzhreg (T *testing. T) {jzhreginfo:=jzhregister{cstmnm:"kingly", Certiftp:"0", Certifid:"612429198812220777", Mobileno:"13410100777",//Mobile phone numberCityid:"5840",//Bank AreaBankID:"113",//BankBANKNM:"Shenzhen Branch",//Branch NameActno:"6230580000144090777",//AccountRemark:"Random Remarks",//Notes} Register (Jzhreginfo)FMT. Println ("---------------------Gold Account Registration------------------------------------------")    FMT. Println ()}//Quick PaymentFunc Testtlquickpay (T *testing. T) {//Request ParametersFasttrx: =quicktradereqfasttrx{Business_code:"19900",//Business codeSubmit_time: Time. Now (). Format ("20060102150405"),//Submission Time (YYYYMMDDHHMMSS)Agrmno:"AIP9549180803000001424",//Agreement Number (the agreement number returned at the time of signing)Account_no:"6214850219949549",//account (debit or credit card)Account_name:"Happiness",//Account name (owner's name on the debit or credit card)AMOUNT:"12345",//Amount (integer, unit)CURRENCY:"CNY",//currency Type (RMB: CNY, HK $: HKD, USD, USD). When not filled in, the default is RMB)Id_type:"0",//type of account opening document (0 ID, 1 hukou, 2 passport, 3 Officer ID, 4 soldier badge ...) )Id:"370613198705308692",//ID NumberTEL:"18689262774",//Phone numberCust_userid:"Github.com/ikaiguang",//Custom user numbers (merchant-defined user numbers that developers can use as Memo fields)SUMMARY:"Transaction PostScript",//transaction PostScript (The transaction notes of the bank to enter the net)REMARK:"unprepared Note",//notes (for merchants to fill in reference information)} result, err:=Allinpay.collect (Fasttrx)ifErr! =Nil {FMT. Printf ("% #v \ n", Err)} FMT. PRINTLN (Result)FMT. Println ("---------------------Quick Payment------------------------------------------")    FMT. Println ()}//Bao pay naked buckleFunc Testbfbarecollect (T *testing. T) {baofoo.barecollect ()FMT. Println ("---------------------Bao pay naked buckle------------------------------------------")    FMT. Println ()}

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.