예제 #1
0
        public async Task Withdraw(WalletRecord walletRecord)
        {
            using (CurrentUnitOfWork.SetTenantId(walletRecord.TenantId))
            {
                string appId = await SettingManager.GetSettingValueForTenantAsync(WechatSettings.General.AppId, walletRecord.TenantId);

                string mchId = await SettingManager.GetSettingValueForTenantAsync(WechatSettings.Pay.MchId, walletRecord.TenantId);

                string key = await SettingManager.GetSettingValueForTenantAsync(WechatSettings.Pay.Key, walletRecord.TenantId);

                UserLogin userLogin = userLoginRepository.GetAll().Where(model => model.UserId == walletRecord.UserId &&
                                                                         model.LoginProvider == "Weixin").FirstOrDefault();

                if (userLogin == null)
                {
                    throw new Exception(L("TheUserHasNoWeixinLogin"));
                }
                string openId = userLogin.ProviderKey;
                string nonce  = TenPayV3Util.GetNoncestr();

                TenPayV3TransfersRequestData TenPayV3TransfersRequestData = new TenPayV3TransfersRequestData(
                    appId,
                    mchId,
                    null,
                    nonce,
                    walletRecord.SerialNumber,
                    openId,
                    key,
                    "NO_CHECK",
                    null,
                    (int)(-walletRecord.Money),
                    L("Withdraw"),
                    IPHelper.GetAddressIP());
                TransfersResult transfersResult = await TransfersAsync(walletRecord.TenantId, TenPayV3TransfersRequestData);

                if (transfersResult.return_code == "FAIL")
                {
                    WalletManager.WithdrawNotify(walletRecord, false, transfersResult.return_msg);
                }
                bool success = transfersResult.result_code == "FAIL" ? false : true;
                WalletManager.WithdrawNotify(walletRecord, success, transfersResult.err_code_des);
            }
        }