1.调用get接口:
Get接口:
[HttpGet]
public async Task
{
var prodStore = await db.B2BProdStores.Where(t => t.ProdId == model.ProdId && t.WareId == model.WareId).FirstOrDefaultAsync();
return Ok(new { ToSellCount = prodStore.ToSellCount });
}
调用:
HttpClient hc = new HttpClient();
string strResult = hc.GetStringAsync(ConfigMgr.Instance.B2BUrl + "doB2B/B2Ba_N_ProdStoreCheck?WareId=" + entity.WareId +"& ProdId = "+taskList.ProdId).Result;
JObject jo = JObject.Parse(strResult);
int ToSellCount = Convert.ToInt32(jo["ToSellCount"].ToString());
if (ToSellCount <= 0) this.Error("指定的商品:" + taskList.ProdName + (taskList.ProdId) + "库存不足");
接口get方法返回list时接口调用:
string url1 = ConfigMgr.Instance.B2BUrl + "doB2B/B2Ba_N_Eb_ProdStore?WareIds=" + model.WareIds;
HttpClient hc = new HttpClient();
var hcResponse = hc.GetAsync(url1).Result;
var resString = hcResponse.Content.ReadAsStringAsync().Result;
if (hcResponse.StatusCode != HttpStatusCode.OK)
{
doServices.Instance.DoLog.Info(doWmsModule.ModuleIdDefine, "请求B2BUrl:" + url1 + ",仓库编码:" + model.WareIds + ",错误信息:" + resString);
this.Error("获取仓库商品信息失败");
}
List>(resString);
foreach (var item in listProdStore)
{
}
*******ConfigMgr.Instance.B2BUrl:域名
GetStringAsync 与 GetAsync两种方法的区别:
1.GetStringAsync.result后无需解析直接用JObject jo = JObject.Parse(strResult);
2.GetAsync需要解析,用:var resString = hcResponse.Content.ReadAsStringAsync().Result;
*********
2.调用post接口:
post接口:
[HttpPost]
public async Task
{
B2CGiftPlan giftPlan = new B2CGiftPlan();
giftPlan.Id = model.Id;
giftPlan.PlanTitle = model.PlanTitle;
giftPlan.PlanIcon = model.PlanIcon;
giftPlan.CashCoupon = model.CashCoupon;
giftPlan.Money = model.Money;
giftPlan.Status = model.Status;
giftPlan.SaleOrderId = model.SaleOrderId;
giftPlan.OrderCreateTime = model.OrderCreateTime;
giftPlan.CreateTime = model.CreateTime;
giftPlan.Comment = model.Comment;
giftPlan.CreateTime = DateTime.Now;
giftPlan.Comment = model.Comment;
db.B2CGiftPlans.Add(giftPlan);
await db.SaveChangesAsync();
return Ok();
}
调用post接口:
GiftPlanVm giftPlan = new GiftPlanVm();
giftPlan.Id = "GSP" + WmsMgr.Instance.Sequence("GiftPlan");
giftPlan.PlanTitle = model.PlanTitle;
giftPlan.PlanIcon = model.PlanIcon;
//对接支付系统
giftPlan.CashCoupon = "";
giftPlan.Money = 0;
giftPlan.Status = GiftPlanStatus.空卡;
giftPlan.SaleOrderId = StoreSendTaskList.RelatedCode;
var Url = ConfigMgr.Instance.B2CUrl+ "doB2C/B2Ca_N_GiftPlan";
HttpClient client = new HttpClient();
var result =client.PostAsJsonAsync(Url, giftPlan).Result;
if(result.StatusCode!= HttpStatusCode.OK)
{
doServices.Instance.DoLog.Info(doWmsModule.ModuleIdDefine, "推送礼品计划失败" + result);
this.Error("礼品计划推送失败");
}
调接口序列化:
string url = ConfigMgr.Instance.EbWebUrl + "doNewB7_Web/B7_N_Eb_VenderAddress";
var hcRechargeTaskresponse = HttpClientHelper.PostAsJsonAsync(url, data).Result;
string resultContent = await hcRechargeTaskresponse.Content.ReadAsStringAsync();
if (hcRechargeTaskresponse.StatusCode != HttpStatusCode.OK)
{
this.Error("同步分销商地址失败");
}
else
{
B_VenderAddressListVm sResult = JsonConvert.DeserializeObject
foreach (var item in sResult.dataList)
{
WmsVenderAddress entity = new WmsVenderAddress();
entity.Id = doServices.Instance.DoCore.getGUID();
entity.VenderId = agentid;
entity.VenderName = item.companyName;
entity.Country = "中国";
entity.Province = item.shipState;
entity.City = item.shipCity;
entity.District = item.shipQX;
entity.Address = item.shipAddr;
entity.IsDefault = YesOrNo.否;
entity.PostCode = item.shipZip;
entity.PersonName = item.shipName;
entity.Phone = item.shipPhone;
entity.Sequence = "";
entity.Remark = item.signStandard;
db.WmsVenderAddresss.Add(entity);
}
await db.SaveChangesAsync();
3.string强制转换int: int ToSellCount = Convert.ToInt32(jo["ToSellCount"].ToString());
4. 身份验证的回调接口:
Dictionary
_signData["AppId"] = ConfigMgr.Instance.AppId;
_signData["BusinessId"] = businessId;
_signData["Message"] = message;
_signData["State"] = state;
string Timestamp = TextHelper.GetSecondTimeStamp();
_signData["Timestamp"] = Timestamp;
string sign = SignData.Md5SignDict(ConfigMgr.Instance.AppKey, _signData);
var dataB2B = new
{
BusinessId = businessId,
Message = message,
State = state,
Timestamp = Timestamp,
Sign = sign,
Sku_ProductNoList = prodStatusItems
};
string B2BUrl = ConfigMgr.Instance.B2BUrl + "doB2B/B2Ba_N_StoreTransTaskCallBackRK"; //B2B
var hcRechargeTaskresponse = HttpClientHelper.PostAsJsonAsync(B2BUrl, dataB2B).Result;
if (hcRechargeTaskresponse.StatusCode != HttpStatusCode.OK)
{
throw new UserException("回掉B2B失败" + hcRechargeTaskresponse.Content.ReadAsStringAsync().Result);
}
签名校验:
Dictionary
signData["time_stamp"] = model.time_stamp;
signData["user_id"] = model.user_id;
signData["card_code"] = model.card_code;
signData["card_password"] = model.card_password;
string sign = SignData.Md5SignDict(B2BConfigMgr.Instance.B2C_AppKey, signData);
if (sign != model.sign) this.Error("签名错误");
注解:1._signData["AppId"] = ConfigMgr.Instance.AppId; appid调用ConfigMgr,ConfigMgr调用json文件
2.签名:sign string sign = SignData.Md5SignDict(ConfigMgr.Instance.AppKey, _signData);
3.时间戳:Timestamp string Timestamp = TextHelper.GetSecondTimeStamp();
4.比较器: Dictionary