淘宝退款接收
This commit is contained in:
@@ -53,6 +53,7 @@ namespace Home.Controllers
|
||||
CouponService m_CouponService;
|
||||
Hncore.Pass.BaseInfo.Service.UserScoreService m_ScoreService;
|
||||
SellerTaoBaoService m_TaoBaoService;
|
||||
TaoBaoRefundService m_TaoBaoRefundService;
|
||||
WxAppUserService m_WxAppUserService;
|
||||
IConfiguration m_Configuration;
|
||||
UserChargeOrderService m_ChargeService;
|
||||
@@ -70,6 +71,7 @@ namespace Home.Controllers
|
||||
,ProductService _ProductService
|
||||
, CouponService _CouponService
|
||||
, SellerTaoBaoService _TaoBaoService
|
||||
, TaoBaoRefundService _TaoBaoRefundService
|
||||
, Hncore.Pass.BaseInfo.Service.UserScoreService _ScoreService
|
||||
, WxAppUserService _WxAppUserService
|
||||
, UserChargeOrderService _ChargeService
|
||||
@@ -88,6 +90,7 @@ namespace Home.Controllers
|
||||
m_PackageService = _PackageService;
|
||||
m_CouponService = _CouponService;
|
||||
m_TaoBaoService = _TaoBaoService;
|
||||
m_TaoBaoRefundService = _TaoBaoRefundService;
|
||||
m_ScoreService = _ScoreService;
|
||||
m_ProductService = _ProductService;
|
||||
m_WxAppUserService = _WxAppUserService;
|
||||
@@ -605,8 +608,10 @@ namespace Home.Controllers
|
||||
AttchInfo = notifyOrder.Tid
|
||||
};
|
||||
var retAmount = await m_UserService.UpdateAmount(amountInfo);
|
||||
|
||||
await m_CouponService.TaoBaoGive(userEntity.Id, 9, userEntity.TaoBao);
|
||||
//判断是否是同一个旺旺
|
||||
if(userEntity.TaoBao != notifyOrder.BuyerNick ){
|
||||
await m_CouponService.TaoBaoGive(userEntity.Id, 9, userEntity.TaoBao);
|
||||
}
|
||||
|
||||
|
||||
var taobaoEntity = notifyOrder.MapTo<TaoBaoOrderEntity>();
|
||||
@@ -617,7 +622,31 @@ namespace Home.Controllers
|
||||
|
||||
return retAmount.Code == ResultCode.C_SUCCESS;
|
||||
};
|
||||
var info = await m_TaoBaoService.ReceivedMsg(this.Request, process);
|
||||
Func<string, Task<bool>> refunds = async (data) =>
|
||||
{
|
||||
var refundInfo = data.FromJsonTo<TaoBaoRefundModel>();
|
||||
|
||||
LogHelper.Info("TaoBao process");
|
||||
if (refundInfo == null || refundInfo.RefundId.NotHas())
|
||||
return false;
|
||||
|
||||
var his_order= m_TaoBaoService.Query(m => m.Tid == refundInfo.Tid).FirstOrDefault();
|
||||
refundInfo.Phone = his_order.Phone;
|
||||
|
||||
var taobaoEntity = refundInfo.MapTo<TaoBaoRefundEntity>();
|
||||
|
||||
await m_TaoBaoRefundService.Add(taobaoEntity);
|
||||
|
||||
return true;
|
||||
};
|
||||
long aopic = long.Parse(this.Request.Query["aopic"]);
|
||||
var info = "";
|
||||
if (aopic == 2){
|
||||
info = await m_TaoBaoService.ReceivedMsg(this.Request, process);
|
||||
} else if(aopic == 256){
|
||||
info = await m_TaoBaoRefundService.ReceivedRefundMsg(this.Request, refunds);
|
||||
|
||||
}
|
||||
return Content(info);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@ namespace Home.Map
|
||||
TinyMapperExtension.Binds<ProductModel, ProductEntity>();
|
||||
|
||||
TinyMapperExtension.Binds<TaoBaoNotifyModel, TaoBaoOrderEntity>();
|
||||
|
||||
TinyMapperExtension.Binds<TaoBaoRefundModel, TaoBaoRefundEntity>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
24
Host/Models/TaoBaoRefundModel.cs
Normal file
24
Host/Models/TaoBaoRefundModel.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Host.Models
|
||||
{
|
||||
public class TaoBaoRefundModel
|
||||
{
|
||||
public string RefundId { get; set; }
|
||||
public string BuyerNick { get; set; }
|
||||
public string RefundFee { get; set; }
|
||||
public string Oid { get; set; }
|
||||
public string Tid { get; set; }
|
||||
public string RefundPhase { get; set; }
|
||||
public string BillType { get; set; }
|
||||
public string SellerNick { get; set; }
|
||||
public string Modified { get; set; }
|
||||
public string Phone { get; set; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -23,6 +23,7 @@ namespace Hncore.Pass.Sells.Domain
|
||||
public virtual DbSet<CouponUserOrginEntity> SellCouponUserOrgin { get; set; }
|
||||
public virtual DbSet<CouponUserUseEntity> SellCouponUserUse { get; set; }
|
||||
public virtual DbSet<TaoBaoOrderEntity> SellerTaoBao { get; set; }
|
||||
public virtual DbSet<TaoBaoRefundEntity> SellerTaoBaoRefund { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
@@ -61,6 +62,13 @@ namespace Hncore.Pass.Sells.Domain
|
||||
entity.Property(e => e.Id).ValueGeneratedOnAdd();
|
||||
});
|
||||
|
||||
modelBuilder.Entity<TaoBaoRefundEntity>(entity =>
|
||||
{
|
||||
entity.ToTable("sell_taobao_refund");
|
||||
entity.HasKey(p => p.Id);
|
||||
entity.Property(e => e.Id).ValueGeneratedOnAdd();
|
||||
});
|
||||
|
||||
base.OnModelCreating(modelBuilder);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
using Hncore.Infrastructure.DDD;
|
||||
using Hncore.Pass.Sells.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Hncore.Pass.Sells.Domain
|
||||
{
|
||||
public partial class TaoBaoRefundEntity
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string RefundId { get; set; }
|
||||
public string BuyerNick { get; set; }
|
||||
public string RefundFee { get; set; }
|
||||
public string Oid { get; set; }
|
||||
public string Tid { get; set; }
|
||||
public string RefundPhase { get; set; }
|
||||
public string BillType { get; set; }
|
||||
public string SellerNick { get; set; }
|
||||
public string Modified { get; set; }
|
||||
public string Phone { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -79,6 +79,55 @@ namespace Hncore.Pass.Sells.Service
|
||||
return "";
|
||||
}
|
||||
|
||||
public async Task<string> ReceivedRefundMsg(HttpRequest request, Func<string, Task<bool>> process)
|
||||
{
|
||||
string appSecret = "xrzmtmfv46mmt9c9rzt2g7c74h9g7u7u";
|
||||
long timestamp = long.Parse(request.Query["timestamp"]);
|
||||
long aopic = long.Parse(request.Query["aopic"]); // 根据aopic判断推送类型
|
||||
string sign = request.Query["sign"];
|
||||
string json = request.Form["json"];
|
||||
|
||||
|
||||
LogHelper.Info("淘宝回调", $"timestamp={timestamp},aopic={aopic},sign={sign},json={json}");
|
||||
|
||||
var dictParams = new Dictionary<string, string>();
|
||||
dictParams.Add("timestamp", timestamp.ToString());
|
||||
dictParams.Add("json", json);
|
||||
var checkSign = Sign(dictParams, appSecret);
|
||||
if (!string.Equals(checkSign, sign))
|
||||
{
|
||||
LogHelper.Error("淘宝回调验签失败", checkSign);
|
||||
return "验签失败";
|
||||
}
|
||||
// 验签通过进行相关的业务
|
||||
|
||||
/*
|
||||
* 返回空字符或者不返回,不进行任何操作
|
||||
* 返回规定格式,进行相应操作。允许的操作有更新发货状态、更新备注、生成旺旺消息
|
||||
* DoDummySend:更新发货状态(false不更新发货状态)
|
||||
* DoMemoUpdate:更新备注(null不更新备注)。Flag是旗帜,可以传0-5的数字,如果传-1或者不传此参数,则保留原旗帜;Memo为备注内容
|
||||
* AliwwMsg:想要发给买家的旺旺消息(null或空字符串,不发消息)
|
||||
*/
|
||||
if (process != null)
|
||||
{
|
||||
if (await process(json))
|
||||
{
|
||||
var returnJson = new
|
||||
{
|
||||
DoDummySend = true,
|
||||
DoMemoUpdate = new
|
||||
{
|
||||
Flag = 1,
|
||||
Memo = "退款处理中"
|
||||
},
|
||||
AliwwMsg = "退款处理中"
|
||||
};
|
||||
return returnJson.ToJson();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
//参数签名
|
||||
public string Sign(IDictionary<string, string> args, string ClientSecret)
|
||||
{
|
||||
|
||||
185
Services/Hncore.Pass.Sells/Service/TaoBaoRefundService.cs
Normal file
185
Services/Hncore.Pass.Sells/Service/TaoBaoRefundService.cs
Normal file
@@ -0,0 +1,185 @@
|
||||
using Hncore.Infrastructure.Common;
|
||||
using Hncore.Infrastructure.Service;
|
||||
using Hncore.Pass.Sells.Domain;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Hncore.Infrastructure.Serializer;
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace Hncore.Pass.Sells.Service
|
||||
{
|
||||
public class TaoBaoRefundService : ServiceBase<TaoBaoRefundEntity>, IFindService
|
||||
{
|
||||
CourseContext m_DbContext;
|
||||
|
||||
public TaoBaoRefundService(
|
||||
CourseContext dbContext
|
||||
,IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
|
||||
{
|
||||
m_DbContext = dbContext;
|
||||
}
|
||||
|
||||
public async override Task<TaoBaoRefundEntity> Add(TaoBaoRefundEntity entity, bool autoSave = true)
|
||||
{
|
||||
if (!this.Exist(m => m.Tid == entity.Tid))
|
||||
{
|
||||
return await base.Add(entity, autoSave);
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
public async Task<string> ReceivedMsg(HttpRequest request, Func<string, Task<bool>> process)
|
||||
{
|
||||
string appSecret = "xrzmtmfv46mmt9c9rzt2g7c74h9g7u7u";
|
||||
long timestamp = long.Parse(request.Query["timestamp"]);
|
||||
long aopic = long.Parse(request.Query["aopic"]); // 根据aopic判断推送类型
|
||||
string sign = request.Query["sign"];
|
||||
string json = request.Form["json"];
|
||||
|
||||
|
||||
LogHelper.Info("淘宝回调", $"timestamp={timestamp},aopic={aopic},sign={sign},json={json}");
|
||||
|
||||
var dictParams = new Dictionary<string, string>();
|
||||
dictParams.Add("timestamp", timestamp.ToString());
|
||||
dictParams.Add("json", json);
|
||||
var checkSign = Sign(dictParams, appSecret);
|
||||
if (!string.Equals(checkSign, sign))
|
||||
{
|
||||
LogHelper.Error("淘宝回调验签失败", checkSign);
|
||||
return "验签失败";
|
||||
}
|
||||
// 验签通过进行相关的业务
|
||||
|
||||
/*
|
||||
* 返回空字符或者不返回,不进行任何操作
|
||||
* 返回规定格式,进行相应操作。允许的操作有更新发货状态、更新备注、生成旺旺消息
|
||||
* DoDummySend:更新发货状态(false不更新发货状态)
|
||||
* DoMemoUpdate:更新备注(null不更新备注)。Flag是旗帜,可以传0-5的数字,如果传-1或者不传此参数,则保留原旗帜;Memo为备注内容
|
||||
* AliwwMsg:想要发给买家的旺旺消息(null或空字符串,不发消息)
|
||||
*/
|
||||
if (process != null)
|
||||
{
|
||||
if (await process(json))
|
||||
{
|
||||
var returnJson = new
|
||||
{
|
||||
DoDummySend = true,
|
||||
DoMemoUpdate = new
|
||||
{
|
||||
Flag = 1,
|
||||
Memo = "购买成功"
|
||||
},
|
||||
AliwwMsg = "购买成功"
|
||||
};
|
||||
return returnJson.ToJson();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public async Task<string> ReceivedRefundMsg(HttpRequest request, Func<string, Task<bool>> refunds)
|
||||
{
|
||||
string appSecret = "xrzmtmfv46mmt9c9rzt2g7c74h9g7u7u";
|
||||
long timestamp = long.Parse(request.Query["timestamp"]);
|
||||
long aopic = long.Parse(request.Query["aopic"]); // 根据aopic判断推送类型
|
||||
string sign = request.Query["sign"];
|
||||
string json = request.Form["json"];
|
||||
|
||||
|
||||
LogHelper.Info("淘宝回调", $"timestamp={timestamp},aopic={aopic},sign={sign},json={json}");
|
||||
|
||||
var dictParams = new Dictionary<string, string>();
|
||||
dictParams.Add("timestamp", timestamp.ToString());
|
||||
dictParams.Add("json", json);
|
||||
var checkSign = Sign(dictParams, appSecret);
|
||||
// if (!string.Equals(checkSign, sign))
|
||||
// {
|
||||
// LogHelper.Error("淘宝回调验签失败", checkSign);
|
||||
// return "验签失败";
|
||||
// }
|
||||
// 验签通过进行相关的业务
|
||||
|
||||
/*
|
||||
* 返回空字符或者不返回,不进行任何操作
|
||||
* 返回规定格式,进行相应操作。允许的操作有更新发货状态、更新备注、生成旺旺消息
|
||||
* DoDummySend:更新发货状态(false不更新发货状态)
|
||||
* DoMemoUpdate:更新备注(null不更新备注)。Flag是旗帜,可以传0-5的数字,如果传-1或者不传此参数,则保留原旗帜;Memo为备注内容
|
||||
* AliwwMsg:想要发给买家的旺旺消息(null或空字符串,不发消息)
|
||||
*/
|
||||
if (refunds != null)
|
||||
{
|
||||
if (await refunds(json))
|
||||
{
|
||||
var returnJson = new
|
||||
{
|
||||
DoDummySend = true,
|
||||
DoMemoUpdate = new
|
||||
{
|
||||
Flag = 1,
|
||||
Memo = "退款处理中"
|
||||
},
|
||||
AliwwMsg = "退款处理中"
|
||||
};
|
||||
return returnJson.ToJson();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
//参数签名
|
||||
public string Sign(IDictionary<string, string> args, string ClientSecret)
|
||||
{
|
||||
IDictionary<string, string> sortedParams = new SortedDictionary<string, string>(args, StringComparer.Ordinal);
|
||||
string str = "";
|
||||
foreach (var m in sortedParams)
|
||||
{
|
||||
str += (m.Key + m.Value);
|
||||
}
|
||||
//头尾加入AppSecret
|
||||
str = ClientSecret + str + ClientSecret;
|
||||
var encodeStr = MD5Encrypt(str).ToUpper();
|
||||
return encodeStr;
|
||||
}
|
||||
|
||||
//Md5摘要
|
||||
public static string MD5Encrypt(string text)
|
||||
{
|
||||
MD5 md5 = new MD5CryptoServiceProvider();
|
||||
byte[] fromData = System.Text.Encoding.UTF8.GetBytes(text);
|
||||
byte[] targetData = md5.ComputeHash(fromData);
|
||||
string byte2String = null;
|
||||
|
||||
for (int i = 0; i < targetData.Length; i++)
|
||||
{
|
||||
byte2String += targetData[i].ToString("x2");
|
||||
}
|
||||
|
||||
return byte2String;
|
||||
}
|
||||
|
||||
|
||||
public async Task<string> Test()
|
||||
{
|
||||
string appSecret = "xrzmtmfv46mmt9c9rzt2g7c74h9g7u7u";
|
||||
long timestamp = 1585122176;
|
||||
long aopic = 2; // 根据aopic判断推送类型
|
||||
string sign = "442B91FB4811A8899EBEA689205F98A1";
|
||||
string json = "{\"Platform\":\"TAOBAO\",\"PlatformUserId\":\"619727442\",\"ReceiverName\":null,\"ReceiverMobile\":\"15538302361\",\"ReceiverPhone\":null,\"ReceiverAddress\":null,\"BuyerArea\":null,\"ExtendedFields\":{},\"Tid\":908706240358624821,\"Status\":\"WAIT_SELLER_SEND_GOODS\",\"SellerNick\":\"可乐开发商\",\"BuyerNick\":\"woai853133256\",\"Type\":null,\"BuyerMessage\":null,\"Price\":\"1.00\",\"Num\":6,\"TotalFee\":\"6.00\",\"Payment\":\"6.00\",\"PayTime\":null,\"PicPath\":\"https://img.alicdn.com/bao/uploaded/i3/619727442/TB2ZSA.XNvxQeBjy0FiXXXioXXa_!!619727442.png\",\"PostFee\":\"0.00\",\"Created\":\"2020-03-25 15:42:50\",\"TradeFrom\":\"WAP,WAP\",\"Orders\":[{\"Oid\":908706240358624821,\"NumIid\":537279953649,\"OuterIid\":null,\"OuterSkuId\":null,\"Title\":\"老客户续费连接\",\"Price\":\"1.00\",\"Num\":6,\"TotalFee\":\"6.00\",\"Payment\":\"6.00\",\"PicPath\":\"https://img.alicdn.com/bao/uploaded/i3/619727442/TB2ZSA.XNvxQeBjy0FiXXXioXXa_!!619727442.png\",\"SkuId\":\"3208012025040\",\"SkuPropertiesName\":\"付费方式:月付;服务器套餐:套餐1;对应金额:1元选项\",\"DivideOrderFee\":null,\"PartMjzDiscount\":null}],\"SellerMemo\":null,\"SellerFlag\":0,\"CreditCardFee\":null}";
|
||||
|
||||
|
||||
var dictParams = new Dictionary<string, string>();
|
||||
dictParams.Add("timestamp", timestamp.ToString());
|
||||
dictParams.Add("json", json);
|
||||
var checkSign = Sign(dictParams, appSecret);
|
||||
if (!string.Equals(checkSign, sign))
|
||||
{
|
||||
LogHelper.Error("淘宝回调验签失败", checkSign);
|
||||
return "验签失败";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user