C # Mobile Recharge

Source: Internet
Author: User
Tags key string openid

C # Mobile Recharge system development (based on aggregated data)

Said is the mobile phone recharge system A little loaded, in fact, is called the aggregation of data payment interface, in fact, quite simple thing but I found that the blog park there is no similar article, I am a bird to my code to contribute to it

First, the preparatory work:

Go to aggregated data request account-add a mobile payment authentication-After the authentication is approved, the account is credited.

Upon completion of the above work, start to prepare the necessary parameters for development:

AppID: In the personal center-my data can be found in the corresponding Appkey (each of the different interfaces need to use the corresponding Appkey)

OpenID: Personal Center-User Center-account information (this is the only program that will be used)

The corresponding interface has a more detailed data receive has been returned parameters of the description, the specific development will be used, specific please see the link: https://www.juhe.cn/docs/api/id/85

The next step is to prepare several helper functions in the development, with sample code in the corresponding API documentation, or use the following:

View Code

The specific functions of these functions are needless to say, is the code is very simple, is the network link to send the request and accept the request is used, I mainly describe the point is not provided in some

The example code used in the Jsonobject this class of code is provided by the CSDN link, unexpectedly still need 2 points to download, Pit Daddy Ah here I share it with you http://pan.baidu.com/s/1hsqF51y

Applying a DLL to a project to join using Xfrog.net; namespaces

The preparation is over.

The next step into the formal coding phase, I would like to start before the focus, in fact, the interface code is not complex, I want to say or thinking it

1. Verify that the current account balance is sufficed recharge: Call Http://op.juhe.cn/ofpay/mobile/yue specific parameters see: https://www.juhe.cn/docs/api/id/85

2. Check whether mobile phone number can recharge: Call Http://op.juhe.cn/ofpay/mobile/telcheck specific parameters see: https://www.juhe.cn/docs/api/id/85/aid/213

3. Call the phone straight to the interface: Http://op.juhe.cn/ofpay/mobile/onlineorder specific parameters See: https://www.juhe.cn/docs/api/id/85/aid/214

4. Call Order Query interface: Http://op.juhe.cn/ofpay/mobile/ordersta specific parameters See: https://www.juhe.cn/docs/api/id/85/aid/586

5. Write callback Processing page: QQ Search aggregated data customer service, give him account and callback address, let him help set, specific callback address accept parameters View: http://code.juhe.cn/docs/detail/id/1565

The specific code is posted:

            1. Account balance Query string url1 = "Http://op.juhe.cn/ofpay/mobile/yue";            var parameters1 = new dictionary<string, string> ();            string timestamp = Gettimestamp (); Parameters1. ADD ("timestamp", timestamp); The current timestamp, such as: 1432788379 parameters1.            ADD ("Key", appkey);//The key you applied for string signstr =openid+ Appkey+timestamp; Parameters1. ADD ("Sign", CommonManager.String.EncryptMD5SystemDefaultMethod (Signstr, False, true)); Checksum value, MD5 (&AMP;LT;B&AMP;GT;OPENID&AMP;LT;/B&AMP;GT;+KEY+TIMESTAMP), OpenID queries string result1 = Sendpost in the Personal center (URL1            , Parameters1, "get");             Jsonobject newObj1 = new Jsonobject (RESULT1); String errorCode1 = newobj1["Error_code"].            Value; Check if the balance is successful if (ErrorCode1 = = "0") {//Determine if the balance is sufficed if (double). Parse (newobj1["Result" ["Money"]. Value) > Double. Parse (integrals)) {//msg. Innertext= "Ample balance!                    ";                    5. Check whether the mobile phone number can recharge string url5 = "Http://op.juhe.cn/ofpay/mobile/telcheck";                    var parameters5 = new dictionary<string, string> (); Parameters5. ADD ("Phoneno", phone); Mobile number PARAMETERS5. ADD ("Cardnum", integrals); Recharge amount, currently available: 5, 10, 20, 30, 50, 100, parameters5.                    ADD ("Key", appkey);//The key you applied for string result5 = Sendpost (URL5, PARAMETERS5, "get");                    Jsonobject newObj5 = new Jsonobject (RESULT5); String ERRORCODE5 = newobj5["Error_code"].                    Value;                        if (ErrorCode5 = = "0") {//can recharge//7. Phone Direct Charging interface                        String url7 = "Http://op.juhe.cn/ofpay/mobile/onlineorder";                        var parameters7 = new dictionary<string, string> (); Parameters7. ADD ("Phoneno", phone); Mobile number PARameters7. ADD ("Cardnum", integrals); Recharge amount, currently available: 5, 10, 20, 30, 50, 100, PARAMETERS7. ADD ("OrderID", ORDERSTR); Merchant Order number, 8-32-digit alphanumeric combination parameters7.                        ADD ("Key", appkey);//You apply for key string md5str = OpenID + appkey + phone + integrals + orderstr; Parameters7. ADD ("Sign", CommonManager.String.EncryptMD5SystemDefaultMethod (Md5str, False, true));                                            Checksum value, MD5 (&lt;b&gt;openid&lt;/b&gt;+key+phoneno+cardnum+orderid), OpenID query in the personal center                        String result7 = Sendpost (Url7, PARAMETERS7, "get");                        Jsonobject NEWOBJ7 = new Jsonobject (RESULT7); String ErrorCode7 = newobj7["Error_code"].                        Value; if (ErrorCode7 = = "0") {msg. InnerText = "top-up order creation is successful, waiting for merchant to recharge and check order status!"                            "; DBSESSION.DEFAULT.FROMSQL (@ "UPDATE TOP (1) tproplOG SET [email protected],[email protected] WHERE ID = @ID "). Addinputparameter ("@ID", Dbtype.int32, ID). Addinputparameter ("@PropStatus", Dbtype.int32, 3). Addinputparameter ("@Jhorderid", dbtype.string, newobj7["Result" ["sporder_id"]. Value).                            Execute (); Status.                        SelectedValue = "3"; } else {msg. InnerText = "Reload order failed!" Reason for failure: "+ newobj7[" Reason "].                        Value; }} else {msg. InnerText = "Mobile phone number cannot recharge!" Reason: "+ newobj1[" Reason "].                    Value; }} else {msg. InnerText = "Insufficient balance please recharge!" The current account balance is: "+ newobj1[" result "[" Money "].                Value;         }} else {        Msg. innertext= "Balance query failed!            "; }

Here are a few points to note:

1. Several interfaces that require sign signing need to use MD5 for a conversion in the format, MD5 the function of the conversion online a lot of trust in your project also I don't have to provide, according to the format he provided to organize the signature.

2. My order query interface is written in another function, because my logical recharge after the individual can be queried, according to the circumstances of their own changes.

3. The callback page is a post-mode value, so the acceptance of the time according to his parameters to receive the line, according to the return order number with the new local data

        Aggregation Call Recharge callback page, page settings need to contact aggregation customer service change protected void Page_Load (object sender, EventArgs e) {var s porder_id = CommonManager.Web.Request ("sporder_id", "");//aggregate order ID var orderid = CommonManager.Web.Request ("Order      ID "," ");               Dingding Order ID var sta = CommonManager.Web.Request ("STA", ""); Recharge Status 1: Success 9: Failure if (STA = = "1") {//Update order status for top up success DbSession.Default.From                        SQL (@ "UPDATE TOP (1) tproplog SET [email protected] WHERE Jhorderid = @Jhorderid") . Addinputparameter ("@PropStatus", Dbtype.int32, 4). Addinputparameter ("@Jhorderid", Dbtype.string, sporder_id).                Execute ();                Response.Clear ();                Response.Write ("Success");            Response.End ();     } if (sta = = "9") {//Update order status for top-up success DBSESSION.DEFAULT.FROMSQL (                   @ "UPDATE TOP (1) tproplog SET [email protected] WHERE Jhorderid = @Jhorderid") . Addinputparameter ("@PropStatus", Dbtype.int32, 5). Addinputparameter ("@Jhorderid", Dbtype.string, sporder_id).                Execute ();                Response.Clear ();                Response.Write ("Success");                Response.End (); Update order status to reload failed}}

Key reviews:

1.jsonobject.dll Download

2. Signature order and character to be provided according to the

3. Callback address to find customer service settings

4. The number of individual mobile phone number and number of times a day limit, more than the number of times will cause the order has been prompted, the last failure, failure will also have a callback prompt

5. When testing, you can map vs Ngrok with the IIS debugging tool to the external network, so that you can directly debug the callback page, another day I will write a simple tutorial, how to use the VS default IIS mapping to the external network for debugging (outside the network debugging can do so, very convenient OH)

C # Mobile Recharge

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.