Asp.net WeChat Pay, sometimes he can pay successfully, but sometimes he will call the payment JSAPI and lack the parameter package.

asp.net WeChat Pay, sometimes he can pay successfully, but sometimes he will call the payment JSAPI and lack the parameter package,. Do you know why?

parameters are not wrong. Appid,server, merchant number and address are all correct, but they still report an error. I hope God will save me

.

related codes

/ / Please paste the code text below (do not replace the code with pictures)

        private void GetUserOpenId()
        {
            string code = Request.QueryString["code"];
            if (string.IsNullOrEmpty(code))
            {
                string code_url = string.Format("https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri={1}&response_type=code&scope=snsapi_userinfo&state=lk-sharpwechat_redirect", "wx97199c27223d23df", "http%3A%2F%2Fhnsthm.cn%2FWap%2Fwxpay%2FUser_WeCha.aspx");
                Response.Redirect(code_url);
            }
            else
            {

                LogUtil.WriteLog(" ============   =====================");

                -sharpregion  OpenID================
                string url = string.Format("https://api.weixin.qq.com/sns/oauth2/access_token?appid={0}&secret={1}&code={2}&grant_type=authorization_code", PayConfig.AppId, PayConfig.AppSecret, code);
                string returnStr = HttpUtil.Send("", url);
                LogUtil.WriteLog("Send   returnStr :" + returnStr);

                var obj = JsonConvert.DeserializeObject<OpenModel>(returnStr);
                /****************************************/

                /****************************************/
                url = string.Format("https://api.weixin.qq.com/sns/oauth2/refresh_token?appid={0}&grant_type=refresh_token&refresh_token={1}", PayConfig.AppId, obj.refresh_token);
                returnStr = HttpUtil.Send("", url);
                obj = JsonConvert.DeserializeObject<OpenModel>(returnStr);

                LogUtil.WriteLog("Send   access_token:" + obj.access_token);
                LogUtil.WriteLog("Send   openid=" + obj.openid);

                /****************************************/

                /****************************************/
                url = string.Format("https://api.weixin.qq.com/sns/userinfo?access_token={0}&openid={1}", obj.access_token, obj.openid);
                returnStr = HttpUtil.Send("", url);
                LogUtil.WriteLog("Send   returnStr:" + returnStr);

                //this.UserOpenId = obj.openid;

                LogUtil.WriteLog(" ============   =====================");

                /****************************************/


                /****************************************/

                /************************************ ******************************************/
                LogUtil.WriteLog("============  ===============");
                PayModel model = new PayModel();
                model.OrderSN = txtOrderSN.Text;
            /*model.TotalFee = int.Parse(rbtlPay.SelectedValue);*/
            model.TotalFee = Convert.ToInt32(0.01);

            //if (rbtlPay.SelectedValue == "0")
            //{
            //    model.TotalFee = Convert.ToInt32(Send.Text);
            //}
            model.Body = txtBody.Text;
                model.OpenId = obj.openid;
                model.Attach = "test";

                string OrderSN = model.OrderSN;
                string Body = model.Body;
                int aa = model.TotalFee * 100;
                string TotalFee = aa.ToString();
                string Attach = model.Attach;
                string UserOpenId = obj.openid;

                LogUtil.WriteLog(string.Format(":OrderSN={0}Body={1}TotalFee={2}Attach={3}UserOpenId={4}",
               //this.OrderSN, this.Body, this.TotalFee, this.Attach, this.UserOpenId));
               OrderSN, Body, TotalFee, Attach, UserOpenId));

                -sharpendregion

                -sharpregion ============================


                -sharpregion ===========================
                // 
                TimeStamp = TenpayUtil.getTimestamp();
                // 
                NonceStr = TenpayUtil.getNoncestr();

                //
                var packageReqHandler = new RequestHandler(Context);
                //
                packageReqHandler.init();

                //package  pdf
                packageReqHandler.setParameter("body", Body); // 127
                packageReqHandler.setParameter("appid", PayConfig.AppId);
                packageReqHandler.setParameter("mch_id", PayConfig.MchId);
                packageReqHandler.setParameter("nonce_str", NonceStr.ToLower());
                packageReqHandler.setParameter("notify_url", PayConfig.NotifyUrl);/***************************************************/
                packageReqHandler.setParameter("openid", UserOpenId);
                packageReqHandler.setParameter("out_trade_no", OrderSN); //
                packageReqHandler.setParameter("spbill_create_ip", Page.Request.UserHostAddress); //ipIP
                packageReqHandler.setParameter("total_fee", TotalFee.ToString()); //,(money * 100).ToString()
                packageReqHandler.setParameter("trade_type", "JSAPI");
                if (!string.IsNullOrEmpty(Attach))
                    packageReqHandler.setParameter("attach", Attach);// 127

                -sharpendregion


                -sharpregion sign===============================
                Sign = packageReqHandler.CreateMd5Sign("key", PayConfig.AppKey);/***************************************************/
                LogUtil.WriteLog("WeiPay   sign:" + Sign);
            -sharpendregion

            -sharpregion package======================
            packageReqHandler.setParameter("sign", Sign);

            string data = packageReqHandler.parseXML();
            LogUtil.WriteLog("WeiPay   packageXML:" + data);

            string prepayXml = HttpUtil.Send(data, "https://api.mch.weixin.qq.com/pay/unifiedorder");
            LogUtil.WriteLog("WeiPay   packageBack_XML:" + prepayXml);

            //ID
            var xdoc = new XmlDocument();
            xdoc.LoadXml(prepayXml);
            XmlNode xn = xdoc.SelectSingleNode("xml");
            XmlNodeList xnl = xn.ChildNodes;
            if (xnl.Count > 7)
            {
                PrepayId = xnl[7].InnerText;
                Package = string.Format("prepay_id={0}", PrepayId);
                LogUtil.WriteLog("WeiPay   package:" + Package);
            }
            -sharpendregion

            /*H5JS*/

            -sharpregion     ==============
            var paySignReqHandler = new RequestHandler(Context);
            paySignReqHandler.setParameter("appId", PayConfig.AppId);
            paySignReqHandler.setParameter("timeStamp", TimeStamp);
            paySignReqHandler.setParameter("nonceStr", NonceStr);
            paySignReqHandler.setParameter("package", Package);
            paySignReqHandler.setParameter("signType", "MD5");
            PaySign = paySignReqHandler.CreateMd5Sign("key", PayConfig.AppKey);

            LogUtil.WriteLog("WeiPay   paySign:" + PaySign);
            -sharpendregion

            -sharpendregion
            }

what result do you expect? What is the error message actually seen?

Apr.03,2021

< H1 > first < / H1 >

package this parameter sends a unified order Api request, and Wechat sends it back to the backend, which is then passed to the frontend for payment.

< H1 > then < / H1 >

1. The value obtained by the frontend should be prepay_id , which is used to assemble package ,
2, and the assembled data 'prepay_id=xxxxxxxxx' is the string content of package.
3. Go to the backend sign .
therefore, this error should be thrown by the front-end , so you need to do a log check, and the problem should come from your data value method at the back end.

< H1 > your code < / H1 >

what is strange is why the subscript is used to find the corresponding parameter, which should be converted to a strongly typed mapping value.
if you do this, what if the order of Wechat's official parameters changes?
can you test whether you can get the value of package?
clipboard.png

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bdd0b8-31355.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bdd0b8-31355.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?