Exemple #1
0
        public object Do_GetExchangeScanCode(BaseApi baseApi)
        {
            string memberId = Utils.GetMemberID(baseApi.token);
            string scanCode = "";

            using (var md5 = MD5.Create())
            {
                var result    = md5.ComputeHash(Encoding.UTF8.GetBytes(Guid.NewGuid().ToString()));
                var strResult = BitConverter.ToString(result);
                scanCode = "EXCHANGE_" + strResult.Replace("-", "");
            }

            ScanExchangeCodeParam scanExchangeCodeParam = new ScanExchangeCodeParam
            {
                code = scanCode,
            };

            ExchangeCode exchangeCode = new ExchangeCode
            {
                code     = scanCode,
                memberId = memberId,
                Unique   = scanExchangeCodeParam.GetUnique(),
            };

            Utils.SetCache(exchangeCode, 0, 0, 30);

            return(scanCode);
        }
Exemple #2
0
        public object Do_Exchange(BaseApi baseApi)
        {
            ExchangeParam exchangeParam = JsonConvert.DeserializeObject <ExchangeParam>(baseApi.param.ToString());

            if (exchangeParam == null)
            {
                throw new ApiException(CodeMessage.InvalidParam, "InvalidParam");
            }

            ScanExchangeCodeParam scanExchangeCodeParam = new ScanExchangeCodeParam
            {
                code = exchangeParam.code
            };

            ExchangeCode exchangeCode = Utils.GetCache <ExchangeCode>(scanExchangeCodeParam);

            if (exchangeCode == null)
            {
                throw new ApiException(CodeMessage.InvalidExchangeCode, "InvalidExchangeCode");
            }

            OpenDao   openDao   = new OpenDao();
            StoreUser storeUser = openDao.GetStoreUser(Utils.GetOpenID(baseApi.token));

            StoreDao storeDao = new StoreDao();
            string   phone    = storeDao.CheckStoreMember(storeUser.storeId, exchangeCode.memberId);

            if (phone == "")
            {
                throw new ApiException(CodeMessage.NeedStoreMember, "NeedStoreMember");
            }

            if (!storeDao.InserRemoteCommit(storeUser.storeId, phone, exchangeParam.score))
            {
                throw new ApiException(CodeMessage.ExchangeError, "ExchangeError");
            }

            Utils.DeleteCache <ExchangeCode>(scanExchangeCodeParam);
            WsPayStateParam wsPayStateParam = new WsPayStateParam
            {
                scanCode = scanExchangeCodeParam.code,
            };
            WsPayState wsPayState = new WsPayState
            {
                wsType = WsType.EXCHANGE,
                Unique = wsPayStateParam.GetUnique(),
            };

            Utils.SetCache(wsPayState, 0, 0, 10);
            return("");
        }