Micro-channel pay personal experience of those pit sandbox environment encountered scan code to pay

Many users scan code to call micro-channel pay payment sandbox environment are bewildered, ado, meet a lot of the pit, in order to let everyone detours directly below I talk about the development of micro-channel pay encounter pits, micro-channel is not an ordinary sandbox the pit is a big pit.

1. First, download the official demo, can not be directly used, which few parameters, few parameters ah, need to follow the official api documentation, control will pass parameters.

2. Unlike other micro-channel pay payment, sandbox environment is the use of the official account, which signkey also acquired according to the official key, sandbox only supports MD5 encryption, and then call after obtaining the interface needs to be replaced when a formal key.

Micro-channel payment acceptance phase can be sandbox testing the payment process

https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=23_1

Proceed as follows

1. address a formal request to modify, add / sandboxnew /

2. Press the formal process do sign

3. official sign, additional calls https://api.mch.weixin.qq.com/sandboxnew/pay/getsignkey get sandbox_signkey

4. Replace the user's own key with sandbox_signkey, do sign signature

5. sign generated from the second to pay off

6. initiate an instant payment notification will be back out

  /// <summary>
        /// 获取沙箱签名密钥。
        /// </summary>
        /// <returns></returns>
        public static string GetSignKey()
        {
            string nonceStr = WxPayApi.GenerateNonceStr();
            WxPayData signParam = new WxPayData();
            signParam.SetValue("mch_id", WxPayConfig.GetConfig().GetMchID());
            signParam.SetValue("nonce_str", nonceStr);
            signParam.SetValue("sign", signParam.MakeSign());
            string xml = signParam.ToXml();
            string url = "https://api.mch.weixin.qq.com/sandboxnew/pay/getsignkey";
            string response = HttpService.Post(xml, url, false, 10);
            Log.Debug("WxPayApi", "GetSignKey response : " + response);
            WxPayData result = new WxPayData();
            SortedDictionary<string, object> items = result.FromXml(response);
            object signKey;
            if (items.TryGetValue("sandbox_signkey", out signKey))
            {
                return signKey.ToString();
            }
            else if (items.TryGetValue("return_msg", out signKey))
            {
                throw new WxPayException(signKey.ToString());
            }
            else
                throw new WxPayException("获取沙箱密钥失败!");
        }

Can also be used POSTMAN get, get to test the long-term key is not valid, valid for three days

3. The important thing to say three times

When micro-channel pay sandbox environment do not sweep the yard, do not sweep the yard, do not sweep the yard, sweep the white sweep, Saowan you will look ignorant force, a two-dimensional code patterns has prompted the original payment URL parameter error, scan mode two codes Tip code has expired, please re-generation. Sandbox environment is directly after the emergence of two-dimensional code interfaces need to call the automated order after five seconds, and then call the inquiry orders interface. He's not real so do not need to pay with a micro-channel scan code.

4. There are places that need attention needs to focus on micro-channel payment acceptance assistant business access, operating in accordance with the acceptance guidelines, there are test cases, it is not free to pay the amount, must be tested in accordance with the amount of test cases.

5. Locate Data.cs file, place the figure in the circle, commented

There are places in the circle in Figure 6, the need to increase ToUpper (), if not out of my code debugging lowercase obtain the signature of the university, resulting in unequal returns false, signature verification error

 

 

Guess you like

Origin www.cnblogs.com/zhaojingwei/p/11262101.html