示例#1
0
        static Payment()
        {
            var type     = typeof(Payment).GetTypeInfo();
            var resource = $"{type.Namespace}.payment.json";

            _config = Wechat.LoadConfiguration <PaymentConfig>(type.Assembly, resource);
        }
示例#2
0
        /// <summary>
        /// 获取某用户微信资料
        /// </summary>
        /// <param name="id">登录用户ID</param>
        /// <returns></returns>
        public static Wechat GetWechatByUserId(int id)
        {
            Wechat wechat = null;
            String sql    = String.Format("SELECT * FROM wechat WHERE user_id = {0}", id);

            using (SQLiteDataReader reader = SQLiteHelper.ExecuteReader(SQLiteHelper.ConnectionStringLocalTransaction, System.Data.CommandType.Text, sql))
            {
                if (reader.Read())
                {
                    wechat = DataRowToModel(reader);
                }
            }
            return(wechat);
        }
        public async Task <string> Get(int id)
        {
            string callbackFunctionName = Request.Query["callback"];
            string type       = Request.Query["type"];
            string sessionKey = Request.Query["sessionKey"];
            string jsCode     = callbackFunctionName + "({\"Status\":\"OK\"});";
            string wechatID   = "";
            string name       = "";
            string imageURL   = "";
            string barcode    = "";

            try
            {
                if (type.Equals("login"))
                {
                    wechatID = Request.Query["wechatID"];
                    name     = Request.Query["name"];
                    imageURL = Request.Query["imageURL"];
                    Wechat   wechat   = this._wechatService.CreateWechat(wechatID, name, imageURL);
                    Customer customer = this._customerService.CreateCustomer(name, name + "@netsdl.com", wechat.Id);
                    Session  session  = this._sessionService.CreateSession(sessionKey, customer.Id);
                }
                ;

                if (type.Equals("barcode"))
                {
                    barcode = Request.Query["barcode"];
                }

                var wechatModel = new WechatViewModel();
                wechatModel.SessionKey     = sessionKey;
                wechatModel.WechatName     = name;
                wechatModel.WechatImageUrl = imageURL;
                wechatModel.Barcode        = barcode;

                await Clients.Group("1").AddFeed(wechatModel);
            }
            catch (Exception ex)
            {
                _loggingRepository.Add(new Error()
                {
                    Message = ex.Message, StackTrace = ex.StackTrace, DateCreated = DateTime.Now
                });
                _loggingRepository.Commit();
            }

            return(jsCode);
        }
示例#4
0
        /// <summary>
        /// 获取符合条件的数据
        /// </summary>
        /// <param name="where">查询条件</param>
        /// <returns>符合条件的数据集</returns>
        public static List <Wechat> GetPeopleByWhere(String where)
        {
            List <Wechat> wechats = new List <Wechat>();

            String sql = String.Format("SELECT * FROM wechats WHERE {0}", where);

            using (SQLiteDataReader reader = SQLiteHelper.ExecuteReader(SQLiteHelper.ConnectionStringLocalTransaction, System.Data.CommandType.Text, sql))
            {
                while (reader.Read())
                {
                    Wechat wechat = DataRowToModel(reader);
                    wechats.Add(wechat);
                }
            }

            return(wechats);
        }
示例#5
0
        /// <summary>
        /// 微信登录
        /// </summary>
        /// <returns></returns>
        public ActionResult Wechat()
        {
            var res = new Wechat().Authorize();

            if (res != null && res.code == 0)
            {
                var m = new ThirdPartyUserModel
                {
                    Uid   = res.result.Value <string>("uid"),
                    Name  = res.result.Value <string>("nickname"),
                    Img   = res.result.Value <string>("headimgurl"),
                    Token = res.token
                };
            }

            return(null);
        }
示例#6
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        private static Wechat DataRowToModel(SQLiteDataReader row)
        {
            Wechat model = new Wechat();

            if (row != null)
            {
                if (row["id"] != null && row["id"].ToString() != "")
                {
                    model.Id = int.Parse(row["id"].ToString());
                }
                if (row["user_id"] != null && row["user_id"].ToString() != "")
                {
                    model.UserId = int.Parse(row["user_id"].ToString());
                }
                if (row["nickname"] != null && row["nickname"].ToString() != "")
                {
                    model.NickName = row["nickname"].ToString();
                }
                if (row["headimgurl"] != null && row["headimgurl"].ToString() != "")
                {
                    model.Headimgurl = row["headimgurl"].ToString();
                }
                if (row["sex"] != null && row["sex"].ToString() != "")
                {
                    model.Gender = "未知";
                    if (Convert.ToInt32(row["sex"].ToString()) == 1)
                    {
                        model.Gender = "男";
                    }
                    else if (Convert.ToInt32(row["sex"].ToString()) == 2)
                    {
                        model.Gender = "女";
                    }
                }
                if (row["created_at"] != null && row["created_at"].ToString() != "")
                {
                    model.CreatedAt = model.ConvertIntDateTime(int.Parse(row["created_at"].ToString()));
                }
                if (row["updated_at"] != null && row["updated_at"].ToString() != "")
                {
                    model.UpdatedAt = model.ConvertIntDateTime(int.Parse(row["updated_at"].ToString()));
                }
            }
            return(model);
        }
        public Wechat CreateWechat(string wechatId, string wechatName, string wechatImageUrl)
        {
            var existingWechat = _wechatRepository.GetSingleByWechatId(wechatId);

            if (existingWechat != null)
            {
                return(existingWechat);
            }

            var wechat = new Wechat()
            {
                WechatId       = wechatId,
                WechatName     = wechatName,
                WechatImageUrl = wechatImageUrl
            };

            _wechatRepository.Add(wechat);
            _wechatRepository.Commit();

            return(wechat);
        }
示例#8
0
        public IActionResult Wechat()
        {
            var res = new Wechat(_contextAccessor).Authorize();

            if (res != null && res.code == 0)
            {
                return(RedirectToLogin(new
                {
                    channel = "wechat",
                    code = 0,
                    user = new
                    {
                        uid = res.result.Value <string>("uid"),
                        name = res.result.Value <string>("nickname"),
                        img = res.result.Value <string>("headimgurl"),
                        token = res.token
                    }
                }));
            }

            return(View());
        }
示例#9
0
        /// <summary>构造微信支付签名</summary>
        /// <remarks>https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=4_3</remarks>
        /// <param name="mchKey">微信支付 API 密钥</param>
        public static string BuildPaySign(Dictionary <string, string> dict, string mchKey)
        {
            var txt = Wechat.BuildSortQueryString(dict) + "&key=" + mchKey;

            return(txt.MD5().ToUpper());
        }
示例#10
0
        //
        // GET: /Home/

        public ActionResult Index()
        {
            Wechat.ProcessRequest();
            return(new EmptyResult());
        }