Пример #1
0
        public async Task <string> SendReq(BaseReq request, string targetAppId = ConstantsAPI.WECHAT_APP_ID)
        {
            int p = 0;

            try
            {
                if (request == null)
                {
                    throw new WXException(1, "Req can't be null.");
                }
                if (string.IsNullOrEmpty(targetAppId))
                {
                    throw new WXException(1, "targetAppID can't be empty.");
                }
                p = 1;
                var data = new TransactData
                {
                    Req          = request,
                    AppId        = _appId,
                    ConmandId    = request.Type(),
                    SdkVersion   = ConstantsAPI.SDK_VERSION,
                    CheckContent = GetCheckContent()
                };
                data.CheckSummary = GetCheckSummary(data.CheckContent, data.SdkVersion, data.AppId);
                p = 2;
                if (string.IsNullOrEmpty(request.Transaction))
                {
                    request.Transaction = GetTransactionId();
                }

                var folder = await ApplicationData.Current.LocalFolder.CreateFolderAsync(ConstantsAPI.SDK_TEMP_DIR_PATH, CreationCollisionOption.OpenIfExists);

                p = 3;
                string fileName = $"{TempFileName}.{targetAppId}";
                //if (await FileUtil.fileExists(fileName))
                //{
                //   await FileUtil.deleteFile(fileName);
                //}
                if (data.ValidateData(false))
                {
                    try
                    {
                        p = 4;
                        TransactData.WriteToFile(data, fileName, ConstantsAPI.SDK_TEMP_DIR_PATH);
                        SendOut(fileName, targetAppId);
                        return("true");
                    }
                    catch (Exception exception)
                    {
                        throw new WXException(0, exception.Message);
                    }
                }
                return("false");
            }
            catch (Exception e)
            {
                return(e.Message + "p:" + p);
            }
        }
Пример #2
0
        public async Task<string> SendReq(BaseReq request, string targetAppId = ConstantsAPI.WECHAT_APP_ID)
        {
            int p = 0;
            try
            {
                if (request == null)
                {
                    throw new WXException(1, "Req can't be null.");
                }
                if (string.IsNullOrEmpty(targetAppId))
                {
                    throw new WXException(1, "targetAppID can't be empty.");
                }
                p = 1;
                var data = new TransactData
                {
                    Req = request,
                    AppId = _appId,
                    ConmandId = request.Type(),
                    SdkVersion = ConstantsAPI.SDK_VERSION,
                    CheckContent = GetCheckContent()
                };
                data.CheckSummary = GetCheckSummary(data.CheckContent, data.SdkVersion, data.AppId);
                p = 2;
                if (string.IsNullOrEmpty(request.Transaction))
                {
                    request.Transaction = GetTransactionId();
                }

                var folder = await ApplicationData.Current.LocalFolder.CreateFolderAsync(ConstantsAPI.SDK_TEMP_DIR_PATH, CreationCollisionOption.OpenIfExists);
                p = 3;
                string fileName = $"{TempFileName}.{targetAppId}";
                //if (await FileUtil.fileExists(fileName))
                //{
                //   await FileUtil.deleteFile(fileName);
                //}
                if (data.ValidateData(false))
                {
                    try
                    {
                        p = 4;
                        TransactData.WriteToFile(data, fileName, ConstantsAPI.SDK_TEMP_DIR_PATH);
                        SendOut(fileName, targetAppId);
                        return "true";
                    }
                    catch (Exception exception)
                    {
                        throw new WXException(0, exception.Message);
                    }
                }
                return "false";
            }
            catch (Exception e)
            {
                return e.Message + "p:" + p;
            }
        }
Пример #3
0
        public bool SendReq(BaseReq request, string targetAppID = "wechat")
        {
            if (request == null)
            {
                throw new WXException(1, "Req can't be null.");
            }
            if (string.IsNullOrEmpty(targetAppID))
            {
                throw new WXException(1, "targetAppID can't be empty.");
            }
            TransactData transactData = new TransactData();

            transactData.Req          = request;
            transactData.AppID        = this.mAppID;
            transactData.ConmandID    = request.Type();
            transactData.SdkVersion   = "1.5";
            transactData.CheckContent = WXApiImplV1.getCheckContent();
            transactData.CheckSummary = WXApiImplV1.getCheckSummary(transactData.CheckContent, transactData.SdkVersion, transactData.AppID);
            if (string.IsNullOrEmpty(request.Transaction))
            {
                request.Transaction = WXApiImplV1.getTransactionId();
            }
            if (!FileUtil.dirExists("wechat_sdk"))
            {
                FileUtil.createDir("wechat_sdk");
            }
            string text = "wechat_sdk\\wp." + targetAppID;

            if (FileUtil.fileExists(text))
            {
                FileUtil.deleteFile(text);
            }
            if (transactData.ValidateData(false))
            {
                try
                {
                    TransactData.WriteToFile(transactData, text);
                    this.sendOut(text, targetAppID);
                    return(true);
                }
                catch (Exception ex)
                {
                    throw new WXException(0, ex.Message);
                }
                //return false;
            }
            return(false);
        }
Пример #4
0
        internal void FromProto(object protoObj)
        {
            if (protoObj == null)
            {
                return;
            }
            TransactDataP transactDataP = protoObj as TransactDataP;

            if (transactDataP == null)
            {
                return;
            }
            this.ConmandID    = (int)transactDataP.ConmandID;
            this.AppID        = transactDataP.AppID;
            this.SdkVersion   = transactDataP.SdkVersion;
            this.CheckContent = transactDataP.CheckContent;
            this.CheckSummary = transactDataP.CheckSummary;
            if (!string.IsNullOrEmpty(transactDataP.GetReq.Base.Transaction))
            {
                this.Req = new GetMessageFromWX.Req();
                this.Req.FromProto(transactDataP.GetReq);
            }
            if (!string.IsNullOrEmpty(transactDataP.AuthReq.Base.Transaction))
            {
                this.Req = new SendAuth.Req();
                this.Req.FromProto(transactDataP.AuthReq);
            }
            if (!string.IsNullOrEmpty(transactDataP.SendReq.Base.Transaction))
            {
                this.Req = new SendMessageToWX.Req();
                this.Req.FromProto(transactDataP.SendReq);
            }
            if (!string.IsNullOrEmpty(transactDataP.ShowReq.Base.Transaction))
            {
                this.Req = new ShowMessageFromWX.Req();
                this.Req.FromProto(transactDataP.ShowReq);
            }
            if (!string.IsNullOrEmpty(transactDataP.GetResp.Base.Transaction))
            {
                this.Resp = new GetMessageFromWX.Resp();
                this.Resp.FromProto(transactDataP.GetResp);
            }
            if (!string.IsNullOrEmpty(transactDataP.AuthResp.Base.Transaction))
            {
                this.Resp = new SendAuth.Resp();
                this.Resp.FromProto(transactDataP.AuthResp);
            }
            if (!string.IsNullOrEmpty(transactDataP.SendResp.Base.Transaction))
            {
                this.Resp = new SendMessageToWX.Resp();
                this.Resp.FromProto(transactDataP.SendResp);
            }
            if (!string.IsNullOrEmpty(transactDataP.ShowResp.Base.Transaction))
            {
                this.Resp = new ShowMessageFromWX.Resp();
                this.Resp.FromProto(transactDataP.ShowResp);
            }
            if (!string.IsNullOrEmpty(transactDataP.PayReq.Base.Transaction))
            {
                this.Req = new SendPay.Req();
                this.Req.FromProto(transactDataP.PayReq);
            }
            if (!string.IsNullOrEmpty(transactDataP.PayResp.Base.Transaction))
            {
                this.Resp = new SendPay.Resp();
                this.Resp.FromProto(transactDataP.PayResp);
            }
        }