Example #1
0
        private static void DoServerNewRequest(object sender, IWebServerRequestContext e)
        {
            var token = e.Context.Request.QueryString["token"];

            UyiDebug.WriteLog($"请求Token:{token}");
            if (string.IsNullOrEmpty(token))
            {
                UyiDebug.WriteLog($"请求Token 为空");
                return;
            }
            var json = e.GetPostData();

            if (string.IsNullOrEmpty(json))
            {
                UyiDebug.WriteLog($"请求Json 为空");
                return;
            }


            UyiDebug.WriteLog($"请求数据:{json}");

            var p = WebParamData.FromJson(json);

            var objectID   = p["objectID"];
            var text       = p["text"];
            var objectType = p["objectType"];
            var action     = p["action"];


            var send_json = BuildDingDingMsg(objectType, objectID, action, text);

            UyiDebug.WriteLog(send_json);
            HttpHelper.PostStringAsync(string.Format(C.HookUrl, token), send_json, HttpHelper.ContextType.JSON);
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public static IWebParamData GetFormParamData(this HttpRequestBase request)
        {
            Saker.Web.WebParamData _query_dic = new WebParamData(true);
            var method = request.HttpMethod;

            foreach (var r in request.Form.AllKeys)
            {
                if (string.IsNullOrEmpty(r))
                {
                    continue;
                }
                var key = r.Trim();
                _query_dic[key] = request.Form[key];
            }

            return(_query_dic);
        }
Example #3
0
        /// <summary>
        /// 获取一个参数的集合列表
        /// </summary>
        /// <param name="request"></param>
        /// <param name="call"></param>
        /// <returns></returns>
        public static IWebParamData GetWebParam(this HttpRequestBase request, Func <string, bool> call)
        {
            Saker.Web.WebParamData _query_dic = new WebParamData(true);
            var method = request.HttpMethod;

            if (method == "GET")
            {
                foreach (var r in request.QueryString.AllKeys)
                {
                    if (string.IsNullOrEmpty(r))
                    {
                        continue;
                    }
                    var key = r.Trim();
                    if (!call(key))
                    {
                        continue;
                    }
                    _query_dic[key] = request.QueryString[key];
                }
            }
            else
            {
                foreach (var r in request.Form.AllKeys)
                {
                    if (string.IsNullOrEmpty(r))
                    {
                        continue;
                    }
                    var key = r.Trim();
                    if (!call(key))
                    {
                        continue;
                    }
                    _query_dic[key] = request.Form[key];
                }
            }

            return(_query_dic);
        }
Example #4
0
        public IActionResult WxAppPay(string appId, string subject, int shopId)
        {
            var    userId    = this.UserInfo.UserId;
            double total_fee = 1;
            string mchId     = "";
            string secret    = "";

            var param = this.GetWebParam();

            if (string.IsNullOrEmpty(appId) ||
                string.IsNullOrEmpty(subject) ||
                shopId == 0
                )
            {
                return(WriteFail("缺少参数"));
            }

            var apiinfo = this.APIKeySecretManager.GetConfigValue(appId, "wxpay");

            if (apiinfo == null)
            {
                return(WriteFail("输入参数 appId 无效"));
            }

            mchId  = apiinfo.AttachParam1;
            secret = apiinfo.AppSecret;

            var trade_no = GetOutTradeNo((int)this.UserInfo.UserId, shopId, out total_fee);

            total_fee *= 100;
            if (string.IsNullOrEmpty(trade_no))
            {
                return(WriteShowTip("生成订单失败"));
            }

            var wxPayRequest = new QL.Web.RestfulApi.WeiXinPayWebParamData();

            wxPayRequest["appid"]            = appId;
            wxPayRequest["mch_id"]           = mchId;
            wxPayRequest["nonce_str"]        = Guid.NewGuid().ToString("n").Substring(0, 8);
            wxPayRequest["body"]             = subject;
            wxPayRequest["out_trade_no"]     = trade_no;
            wxPayRequest["total_fee"]        = total_fee.ToString("0");
            wxPayRequest["spbill_create_ip"] = this.ClientIpAdress;

            if (this.ConfigManager.UseHttps != 0)
            {
                wxPayRequest["notify_url"] = $"https://{RequestHost}/pay/PayCallback.WxPay";
            }
            else
            {
                wxPayRequest["notify_url"] = $"http://{RequestHost}/pay/PayCallback.WxPay";
            }
            //wxPayRequest["attach"] = attach.ToUrl();
            wxPayRequest["trade_type"] = "APP";

            wxPayRequest["sign"] = wxPayRequest.MarkSign(false, secret);
            var xmlbody    = wxPayRequest.ToXml();
            var result_xml = HttpHelper.PostString(wxpayunifiedorder, xmlbody);


            var result       = WebParamData.FromXml(result_xml);
            var appWxPayData = new QL.Web.RestfulApi.WeiXinPayWebParamData();

            if (result["return_code"] != "SUCCESS")
            {
                appWxPayData["status"] = "fail";
                appWxPayData["msg"]    = result["return_msg"];
                return(Json(appWxPayData));
            }
            appWxPayData["appid"]     = appId;
            appWxPayData["partnerid"] = mchId;
            appWxPayData["prepayid"]  = result["prepay_id"];
            appWxPayData["package"]   = "Sign=WXPay";
            appWxPayData["timestamp"] = QL.Security.Encryption.EncryptionHelper.GetTimeStamp();
            appWxPayData["noncestr"]  = Guid.NewGuid().ToString("n").Substring(0, 8);
            appWxPayData["sign"]      = appWxPayData.MarkSign(false, secret);
            appWxPayData["status"]    = "success";
            appWxPayData["msg"]       = "OK";

            return(Json(appWxPayData));
        }
Example #5
0
        public IActionResult WxWapPay(string appId, string subject, int shopId)
        {
            var    userId    = this.UserInfo.UserId;
            double total_fee = 1;
            string mchId     = "";
            string secret    = "";

            var param = this.GetWebParam();

            if (string.IsNullOrEmpty(appId) ||
                string.IsNullOrEmpty(subject) ||
                shopId == 0
                )
            {
                return(WriteFail("缺少参数"));
            }

            var apiinfo = this.APIKeySecretManager.GetConfigValue(appId, "wxpay");

            if (apiinfo == null)
            {
                return(WriteFail("输入参数 appId 无效"));
            }

            mchId  = apiinfo.AttachParam1;
            secret = apiinfo.AppSecret;

            var trade_no = GetOutTradeNo((int)this.UserInfo.UserId, shopId, out total_fee);

            total_fee *= 100;

            if (string.IsNullOrEmpty(trade_no))
            {
                return(WriteShowTip("生成订单失败"));
            }



            var wxPayRequest = new QL.Web.RestfulApi.WeiXinPayWebParamData();

            wxPayRequest["appid"]            = appId;
            wxPayRequest["mch_id"]           = mchId;
            wxPayRequest["nonce_str"]        = Guid.NewGuid().ToString("n").Substring(0, 8);
            wxPayRequest["body"]             = subject;
            wxPayRequest["out_trade_no"]     = trade_no;
            wxPayRequest["total_fee"]        = total_fee.ToString("0");
            wxPayRequest["scene_info"]       = WxWapPaySceneInfo;
            wxPayRequest["spbill_create_ip"] = this.ConfigManager.ServicesIp;

            if (this.ConfigManager.UseHttps != 0)
            {
                wxPayRequest["notify_url"] = $"https://{RequestHost}/pay/PayCallback.WxPay";
            }
            else
            {
                wxPayRequest["notify_url"] = $"http://{RequestHost}/pay/PayCallback.WxPay";
            }
            wxPayRequest["trade_type"] = "MWEB";
            wxPayRequest["sign"]       = wxPayRequest.MarkSign(false, secret);
            var xmlbody = wxPayRequest.ToXml();

            this.WriteLog($@"支付下单请求参数:
{xmlbody}");

            var unifiedorderResultXml = HttpHelper.PostString("https://api.mch.weixin.qq.com/pay/unifiedorder", xmlbody);

            this.WriteLog(unifiedorderResultXml);

            var unifiedorderResult = WebParamData.FromXml(unifiedorderResultXml);

            {
                //处理下订单的结果
                var return_code = unifiedorderResult["return_code"];
                var return_msg  = unifiedorderResult["return_msg"];

                if (return_code != "SUCCESS")
                {
                    this.WriteLog($@"支付下单操作结果:{return_msg}");
                    return(WriteFail("支付下单失败"));
                }
            }

            {
                //处理下订单的结果
                var return_code = unifiedorderResult["return_code"];
                var return_msg  = unifiedorderResult["return_code"];
            }

            var    mweb_url = unifiedorderResult["mweb_url"];
            string payUrl   = mweb_url;

            if (string.IsNullOrEmpty(payUrl))
            {
                return(WriteFail("支付下单失败!"));
            }

            var res = HttpHelper.GetString(mweb_url, $@"http://{RequestHost}/{RequestPath}");


            const string pattern      = @"weixin://wap/pay?.*?(?="";)";
            var          reg          = new System.Text.RegularExpressions.Regex(pattern);
            var          matachs_cols = reg.Matches(res);

            if (matachs_cols.Count <= 0)
            {
                this.WriteLog("支付地址获取失败1");
                goto Result;
            }
            payUrl = matachs_cols[0].Value;
            if (string.IsNullOrEmpty(payUrl))
            {
                this.WriteLog("支付地址获取失败2");
                payUrl = mweb_url;
                goto Result;
            }

Result:
            return(Json(new
            {
                status = "success",
                msg = "OK",
                payUrl = payUrl
            }));
        }
Example #6
0
        private IActionResult ProcessUserLogonResponse(UserLogonCatchInfo userinfo)
        {
            IWebParamData param = null;

            //尝试获取该用户的分享参数
            //if (!string.IsNullOrEmpty(userinfo.UnionID))
            //{
            //    try
            //    {
            //        var url = RedisTools.ReadShareParam(userinfo.UnionID);
            //        if (!string.IsNullOrEmpty(url))
            //        {
            //            param = Uyi.Web.WebParamData.FromUrl(url);
            //        }
            //    }
            //    catch { }
            //}
            if (param == null)
            {
                param = new WebParamData();
            }

            int parentUser = 0;
            //if (!int.TryParse(param["parent"], out parentUser))
            //{
            //    int.TryParse(context.Request["parent"], out parentUser);
            //}


            //初始化数据
            string openid   = userinfo.OpenID;
            string unionId  = userinfo.UnionID;
            string headimg  = userinfo.HeadImg;
            string nickname = userinfo.NickName;

            //调用数据接口
            DataSet ds;

            int retVal = do_WEB_ALL_UserLogon(unionId, userinfo, userinfo.SNSID, out ds);

            this.WriteLog($"玩家登陆:retVal = {retVal}");
            switch (retVal)
            {
            case 1: break;

            case -2:
            {
                return(Json(new
                    {
                        status = "showbox",
                        msg = "您的账号已被封停,请联系客服",
                    }));
            }

            default:
            {
                return(Json(new
                    {
                        status = "showtip",
                        msg = "服务器维护中...",
                    }));
            }
            }

            var dr     = ds.Tables[0].Rows[0];
            var userid = dr.GetData("userid").ConvertToUInt32();

            if (userid <= 0)
            {
                return(WriteFail("登录失败"));
            }

            //userinfo.HeadImg = userinfo.HeadImg;
            //userinfo.NickName = dr["nickname"].ToString();

            var catch_userTokken = GetCatchUserToken(userinfo);

            param["status"]      = "success";
            param["accesstoken"] = GetUserAccessToken(userid);
            param["catchtoken"]  = catch_userTokken;

            //UyiDebug.WriteLog($"用户APP登录输出:{param.ToJson()}");

            //响应结果数据
            return(Json(param));
        }