|
@@ -11,13 +11,15 @@ namespace MySystem
|
|
|
{
|
|
|
public class AlipayFunction
|
|
|
{
|
|
|
+ public readonly static AlipayFunction Instance = new AlipayFunction();
|
|
|
+ private AlipayFunction()
|
|
|
+ { }
|
|
|
+
|
|
|
private string AppId = "2021003116616751";
|
|
|
private string PrivateKey = "MIIEpAIBAAKCAQEA1KjMzZJIRG6QQ3+c/euVrc+8RR0xMw6A+EONSKhJq4Bg+rtxQPCfdF2bpZ4NMaSqfalSiLoxrZSYBYOZhpDP67i9LXGUoFCWdRL7ROTqJvuU6KyEeMplQ6Q3uwWbuKbh9COt0vhqn/pjlUsomTwq+DRQv10awynkZikqceXdP0EH4iGZG0hyerEP5yLHpHiggf4f7TOsovHX+fGLPmWFO1zUTHHbz7HxU4BQKn3yuje4yMhoyv5h/wZzeVwvj+Qti8Hlh351rF0f5BHwN1YMGIrWuPU5bF8OMHS/UXPxh7Bs795ZZyplYztTz26QfKfLWVVsLOng4pvgPS+OgzZydwIDAQABAoIBAEu6mMQT9Zw46zK+PP/HZxPwSBEsphqSbab7F1LqauGh4+cl3NzNU1szAnxl3jjxdK0vIO8DrzErGz/Lb16WLxS4QtXt/olgaVPjoIsWIbQkHxEEbmA9YvZFgnsdMij9dLVmBz57rCywE8pUa262GG8u4hpjY2Zggq9GtZC91J3zOeETBG828gU+FLHGcDpfz7pD1jC0noDfDRxmIImOMZvChIvvY+tm6MpySXN8lw1vxhLc0aZbKSQkuVyCyB4fIsdJJvh2dRPiY+BA0jXNK3mWwnnHzac/9JXqWFlwk6iPIIjXPUldz7Zq3EpCI+9p+UqLtIu6BAUbk1biFTt8xMECgYEA+2iIxZfdl1N1suA/aEbUdjd0kxeeOsGv7Ps0rOYn+4/q1dkUukg2V6VRy3E8BUt+9zLPTR8DmL7oBi+kDsGehjHlH7U6Pe8qKszB4ufQBDHc71yg9liqOWa4s9VoBD0VIU9CO0HtYjRor7rVuUzp+j58SLP7wIEPGEwdgjeYENECgYEA2IsYEyHiwhjy5r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PS+OgzZydwIDAQAB";
|
|
|
private string AlipayPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxycehrmnTl2IaIAECP+0HWc1eWGM/T6x022K7K6fdf+xoyC97TBJaG4G3Bcon4gsJX+Sad5IA9OJIQ4eN1joM35hIlwcFZ6MmCuVXx/SMAKThIjK0jsRc6aTxVQG+GVCgS7dXMKb4Sm+vK2wEM6xtDeqcfYMB0BqGZRvxbIV59a2ooPrha4FkV6nNC9DQefzC0picHXV64oYUjMM2ed4ASTQVds7HP9BZfalz//APZcWdBV08f+xv7n79Twz/gNtVAadfuTAlcjsS6aK+G/OrZtr/diuemeRPRUKlVhcr5xOQDhqBgtdIw8M9Wp6I4ULXRlthKVBWToH9j6n9vDIiwIDAQAB";
|
|
|
- public AlipayFunction()
|
|
|
- {
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
|
|
|
#region 代商家签约
|
|
@@ -339,18 +341,27 @@ namespace MySystem
|
|
|
|
|
|
#region 退款
|
|
|
|
|
|
- public string Refund(string TradeNo, string Amount, string Token)
|
|
|
+ public string Refund(string TradeNo, string Amount, string MerPid, string Reason = "")
|
|
|
{
|
|
|
IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", AppId, PrivateKey, "json", "1.0", "RSA2", AlipayPublicKey, "utf-8", false);
|
|
|
AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
|
|
|
request.BizContent = "{" +
|
|
|
"\"trade_no\":\"" + TradeNo + "\"," +
|
|
|
- "\"refund_amount\":" + Amount + "" +
|
|
|
+ "\"refund_amount\":" + Amount + "," +
|
|
|
+ "\"out_request_no\":\"" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8) + "\"," +
|
|
|
+ "\"refund_reason\":\"" + Reason + "\"," +
|
|
|
+ "\"refund_royalty_parameters\":[{" +
|
|
|
+ "\"royalty_type\":\"transfer\"," +
|
|
|
+ "\"trans_out_type\":\"userId\"," +
|
|
|
+ "\"trans_out\":\"" + MerPid + "\"," +
|
|
|
+ "\"amount\":" + Amount + "," +
|
|
|
+ "\"desc\":\"" + Reason + "\"" +
|
|
|
+ "}]" +
|
|
|
"}";
|
|
|
string result = "";
|
|
|
try
|
|
|
{
|
|
|
- AlipayTradeRefundResponse response = client.Execute(request, null, Token);
|
|
|
+ AlipayTradeRefundResponse response = client.Execute(request, null, "202306BB117e046cfc29434c8f4acfd2a43aeX03");
|
|
|
result = response.Body;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
@@ -372,11 +383,11 @@ namespace MySystem
|
|
|
foreach (RoyaltyParameters Parameter in Parameters)
|
|
|
{
|
|
|
royalty_parameters += " {" +
|
|
|
- " \"royalty_type\":\"transfer\"," +
|
|
|
- " \"trans_in_type\":\"loginName\"," +
|
|
|
+ // " \"royalty_type\":\"transfer\"," +
|
|
|
+ // " \"trans_in_type\":\"loginName\"," +
|
|
|
" \"trans_in\":\"" + Parameter.Account + "\"," +
|
|
|
- " \"amount\":" + Parameter.Amount + "," +
|
|
|
- " \"trans_in_name\":\"" + Parameter.Name + "\"" +
|
|
|
+ " \"amount\":" + Parameter.Amount + "" +
|
|
|
+ // " \"trans_in_name\":\"" + Parameter.Name + "\"" +
|
|
|
" },";
|
|
|
}
|
|
|
request.BizContent = "{" +
|
|
@@ -389,7 +400,67 @@ namespace MySystem
|
|
|
string result = "";
|
|
|
try
|
|
|
{
|
|
|
- AlipayTradeOrderSettleResponse response = client.Execute(request);
|
|
|
+ AlipayTradeOrderSettleResponse response = client.Execute(request, null, "202306BB117e046cfc29434c8f4acfd2a43aeX03");
|
|
|
+ result = response.Body;
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ function.WriteLog(ex.ToString(), "分账异常");
|
|
|
+ result = "";
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 绑定分账关系
|
|
|
+ public string BindSettleRelation(string RequestNo, string Account)
|
|
|
+ {
|
|
|
+ IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", AppId, PrivateKey, "json", "1.0", "RSA2", AlipayPublicKey, "utf-8", false);
|
|
|
+ AlipayTradeRoyaltyRelationBindRequest request = new AlipayTradeRoyaltyRelationBindRequest();
|
|
|
+ request.BizContent="{" +
|
|
|
+ " \"receiver_list\":[" +
|
|
|
+ " {" +
|
|
|
+ " \"type\":\"userId\"," +
|
|
|
+ " \"account\":\"" + Account + "\"" +
|
|
|
+ // " \"name\":\"测试名称\"," +
|
|
|
+ // " \"memo\":\"分账给测试商户\"," +
|
|
|
+ // " \"login_name\":\"test@alitest.xyz\"," +
|
|
|
+ // " \"bind_login_name\":\"test@alitest.xyz\"" +
|
|
|
+ " }" +
|
|
|
+ " ]," +
|
|
|
+ " \"out_request_no\":\"" + RequestNo + "\"" +
|
|
|
+ "}";
|
|
|
+ string result = "";
|
|
|
+ try
|
|
|
+ {
|
|
|
+ AlipayTradeRoyaltyRelationBindResponse response = client.Execute(request, null, "202306BB117e046cfc29434c8f4acfd2a43aeX03");
|
|
|
+ result = response.Body;
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ function.WriteLog(ex.ToString(), "绑定分账关系异常");
|
|
|
+ result = "";
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 查看分账
|
|
|
+ public string QuerySettle(string OrderNo, string TradeNo)
|
|
|
+ {
|
|
|
+ IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", AppId, PrivateKey, "json", "1.0", "RSA2", AlipayPublicKey, "utf-8", false);
|
|
|
+ AlipayTradeOrderSettleQueryRequest request = new AlipayTradeOrderSettleQueryRequest();
|
|
|
+ request.BizContent="{" +
|
|
|
+ " \"settle_no\":\"20210706002530020036530021395831\"," +
|
|
|
+ " \"out_request_no\":\"20210727001\"," +
|
|
|
+ " \"trade_no\":\"2021112611001004680 073956707\"" +
|
|
|
+ "}";
|
|
|
+ string result = "";
|
|
|
+ try
|
|
|
+ {
|
|
|
+ AlipayTradeOrderSettleQueryResponse response = client.Execute(request, null, "202306BB117e046cfc29434c8f4acfd2a43aeX03");
|
|
|
result = response.Body;
|
|
|
}
|
|
|
catch (Exception ex)
|