The extra money we've earned in those years. (POS (mobile payment) interface development)

Source: Internet
Author: User

The ritual came forward. In my Blog " Those years we earned the extra money " before and after the big small also took a few reverse telecommuting, this time is because of the long have not written blog, hot to share. Recently back to the second-tier city near the hometown of Chengdu work, income that is a lot of decline ah, just started the wife has not said anything, with the beginning of mortgage and debt, life began to be stretched. Hey, I've been worrying about how to increase your income lately! His idea is: 1, to try to do more than a few Android app released to the major markets, rely on the placement of advertising to earn some cabbage money. (not verified if it is feasible) 2, the previous accumulated many years of industry management software needs to be organized into several software, or based on cloud services to create several shared software. (Competition is very fierce ah, easy to die on the beach and halfway) 3, online find a part-time 4, pick up some reverse telecommuting. Last night, I saw Xiaotie Tico's blog < beliefs, thoughts, actions-talk about the programmer's return to his hometown of entrepreneurship > Some feelings, I hope to take this article to discuss the topic again.

1. Requirements and Interface documentation

Description : This is a small single that has been stretched out before the reverse telecommuting. is to make an interface program and integrate with the previous business system (partially outsourced to myself).

2, the process of coding and problems encountered

code length : About 3 hours.

Coding tool : VS2010

problem encountered : C # calls the VC's dynamic library, the external reference DLL parameter type corresponds to the problem.

Function prototype: (interface:int Abmcs (char *request, char *response);)

The first version of the wording:

[DllImport ("Xgd_dll.dll", CharSet = CharSet.Ansi)]
unsafe public static extern int Abmcs (string request, out StringBuilder response);

Results reported that the memory can not write anything, VC out of the argument char * should be a pointer, do not know what type to correspond, before looking at someone else to write StringBuilder to pick up can be.

Ah, or the foundation is not good ah, with a string of what have tried, or not, and then thought of using the pointer, obviously this is C # not recommended practice, I claim that the birds actually did not use the pointer in C #, estimated that a lot of friends have to look down,

On this level to connect reverse telecommuting, also dare call the veteran!

The second version of the wording:

[DllImport ("Xgd_dll.dll", CharSet = CharSet.Ansi)]
unsafe public static extern int Abmcs (string request, byte* response);

String requesttxt = Request. Getrequeststring ();
byte[] buffer = new byte[144];
Unsafe
{
Fixed (byte* array = buffer)
{
Abmcs (requesttxt, array);
return new Bankresponseentity (Encoding.Default.GetString (buffer));
}
}

Pass! For the requirements of "know it is OK, you can not know it" of the CTRL + V Dafa Deep worship I am satisfied with the smile.

encoding Process :

1) Arrange the idea, according to the document sorting out the class diagram (brain map, did not draw out drops).

2) to write, and then encounter a problem Baidu (recently Google can not access AH), finally a pit, fix.

Results :

Here's some code :

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespacemisposinterfacelib{/// <summary>    ///Transaction Request Entity/// </summary>     Public classposrequestentity {protected string_transactiontypeflag;  PublicPosrequestentity (stringtransactiontype) {_transactiontypeflag=Transactiontype; }         Public stringValue1 {Get; Set; }         Public stringValue2 {Get; Set; }         Public stringValue3 {Get; Set; }         Public stringValue4 {Get; Set; }         Public stringValue5 {Get; Set; }        /// <summary>        ///GET Request Text/// </summary>        /// <returns></returns>         Public stringgetrequeststring () {return string. Join ("|",New string[] {_transactiontypeflag, Value1, Value2, Value3, Value4, Value5,"" }); }    }}
Message interaction entity class definition
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespacemisposinterfacelib{/// <summary>    ///POS Reply entity class/// </summary>     Public classbankresponseentity {protected string_resultresponse;  PublicBankresponseentity (stringresultresponse) {_resultresponse=Resultresponse;        Splitresponse (); }        protected voidSplitresponse () {string[] Temparray = _resultresponse.split ("|".            ToCharArray ()); if(Temparray.length >Ten) {ResultCode= temparray[0]; Authorization Code= temparray[1]; Card number= temparray[2]; Amount= temparray[3]; System Reference Number= temparray[4]; Valid date= temparray[5]; Trading Date= temparray[6]; Trading Hours= temparray[7]; Messagecontext= temparray[8]; Merchant Number= temparray[9]; Terminal number= temparray[Ten]; }        }        /// <summary>        ///Reply Code 00 indicates success/// </summary>         Public stringResultCode {Get; Set; }         Public stringAuthorization Code {Get; Set; }         Public stringCard Number {Get; Set; }         Public stringAmount {Get; Set; }         Public stringSystem Reference Number {Get; Set; }         Public stringvalid Date {Get; Set; }         Public stringTransaction Date {Get; Set; }         Public stringTrading Hours {Get; Set; }         Public stringMessagecontext {Get; Set; }         Public stringMerchant Number {Get; Set; }         Public stringTerminal number {Get; Set; }        /// <summary>        ///whether the transaction request was successful/// </summary>         Public BOOLTransactionresultvalue {Get            {                returnResultcode.equals ("xx"); }        }    }}
POS Return message entity definition
Using system;using system.collections.generic;using system.linq;using system.text;using System.runtime.interopservices;namespace misposinterfacelib{///<summary>//POS Transaction Business class///</summary&gt    ;        public class Mispostransaction:imispostransaction {[DllImport ("Xgd_dll.dll", CharSet = CharSet.Ansi)]        unsafe public static extern int Abmcs (string request, byte* response); <summary>///Like a POS machine to initiate a transaction request///</summary>//<param name= "Request" ></param >//<returns></returns> public bankresponseentity sendtransactionrequest (posrequestentity R Equest) {String requesttxt = Request.            Getrequeststring ();            byte[] buffer = new byte[144]; unsafe {fixed (byte* array = buffer) {Abmcs (Requesttxt, Arra                    y); return new Bankresponseentity (Encoding.Default.GetString (buffer));               }            }        }    }} 

Calling interface:

Using system;using system.collections.generic;using system.linq;using system.text;using MisposInterfaceLib; Namespace miposinterface{    class program    {        static void Main (string[] args)        {            imispostransaction Consumetransaction = new Mispostransaction ();            Posrequestentity signinrequest = new Posrequestentity (transactiontype.consumeflag)            {                Value1 = "3098234.98",                Value2 = "111111",                Value3 = "222222",                Value4 = "123456",                Value5 = "333333"            };            var result =  Consumetransaction.sendtransactionrequest (signinrequest);            Console.WriteLine (Result. Messagecontext);}}}    

  

  

Well, over and over, the article is still too short of nutrition (finally a little self-knowledge is clear). But I do not know why this late is not sleepy, I hope today's hard work can usher in the consolation prize of life.

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.