You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/Areas/Account/DAL/Chfee_invoice_HangXin/Helper.cs

131 lines
3.8 KiB
C#

3 years ago
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
using NuonuoSDK;
namespace DSWeb.Areas.Account.Helper
{
//从DSWeb.Areas.Dispatch.Helper public static class WebRequestHelper中复制
public class HangXinRequestHelper
{
private string appKey { get; set; }
private string appSecret { get; set; }
private static string MerchantToken { get; set; }
private string code { get; set; }
private string taxnum { get; set; }
private string redirectUri { get; set; }
private static string ISVToken { get; set; }
private string sandboxUrl = "https://sandbox.nuonuocs.cn/open/v1/services";
private string normalUrl = "https://sdk.nuonuo.com/open/v1/services";
private static string _url { get; set; }
public string url
{
get
{
if (string.IsNullOrEmpty(_url))
{
//正式使用时切换成normalUrl
return sandboxUrl;
}
else return _url;
}
set {
_url = value;
}
}
/// <summary>
/// 商户获取访问令牌
/// </summary>
/// <returns></returns>
public string getMerchantToken()
{
//string appKey = "your.appKey";
//string appSecret = "your.appSecret";
return NNOpenSDK.getMerchantToken(appKey, appSecret);
}
private void setMerchantToken() {
MerchantToken = getMerchantToken();
}
/// <summary>
/// ISV获取访问令牌
/// </summary>
/// <returns></returns>
public string getISVToken()
{
//string code = "your.code";
//string appKey = "your.appKey";
//string appSecret = "your.appSecret";
//string taxnum = "your.taxnum";
//string redirectUri = "your.redirectUri";
return NNOpenSDK.getISVToken(appKey, appSecret, code, taxnum, redirectUri);
}
private void setISVToken()
{
ISVToken = getISVToken();
}
/// <summary>
/// ISV获取刷新令牌
/// </summary>
/// <returns></returns>
public string refreshISVToken()
{
//string userId = "your.userId";
//string refreshToken = "your.refreshToken";
//string appSecret = "your.appSecret";
return NNOpenSDK.refreshISVToken(refreshToken, userId, appSecret);
}
public string setrefreshISVToken() {
ISVToken = refreshISVToken();
}
public HangXinRequestHelper() {
}
public HangXinRequestHelper(string Key, string Secret,string Url="") {
appKey = Key;
appSecret = Secret;
url = Url;
setMerchantToken();
}
public string PostInvoice(string json){
string senid = Guid.NewGuid().ToString().Replace("-", "").Substring(0, 32); // 唯一标识由企业自己生成32位随机码
//string method = "nuonuo.electronInvoice.CheckEInvoice";
string method = "nuonuo.electronInvoice.requestBilling";
string result = NNOpenSDK.sendPostSyncRequest(sandboxUrl, senid, appKey, appSecret, token, taxnum, method, content);
}
public HangXinRequestHelper(string Key, string Secret,string code,string taxnum,string redirectUri, string Url = "")
{
appKey = Key;
appSecret = Secret;
url = Url;
this.code = code;
this.taxnum = taxnum;
this.redirectUri = redirectUri;
setISVToken();
}
}
}