下面是c#实现返利接口的部分代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | [HttpPost] public async Task FanliAsync(string appkey) { WeixinTBKConfigEntity configEntity = GetConfigEntity(appkey); if (configEntity == null) { LogHelper.WriteLog(typeof(OtherWechatController), appkey接口验证时,appkey不存在); return Content(验证失败。appkey接口验证时,appkey不存在); } Request.InputStream.Position = 0; Stream stream = Request.InputStream; string json = string.Empty; if (stream.Length != 0) { StreamReader streamreader = new StreamReader(stream); json = streamreader.ReadToEnd(); } WeChatToolMessage responseMsg = new WeChatToolMessage(); if (string.IsNullOrEmpty(json)) { return Json(responseMsg); } WeChatToolMessage msg = JsonConvert.DeserializeObject(json); if (string.IsNullOrEmpty(msg.wxid) || string.IsNullOrEmpty(msg.content)) { return Json(responseMsg); } string content = msg.content; string responseStr = string.Empty; if (content.Contains(yangkeduo.com)) { //访问拼多多接口 responseStr = await GetPddCouponAsync(configEntity, msg); } else if (content.Contains(jd.com)) { if (!string.IsNullOrEmpty(configEntity.JdPID)) { //访问京东联盟接口 responseStr = GetJdCoupon(configEntity, msg); } } else { //访问淘宝联盟接口 responseStr = GetTBKCouponByPassword(configEntity, msg.content); } responseMsg.wxid = msg.wxid; responseMsg.content = responseStr; return Json(responseMsg); } |
发布接口之后将接口地址填入微信助手“自动回复”菜单url输入框中,如下图所示: