OpenApi.java 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package openapi.tools.nuonuo;
  2. import net.sf.json.JSONObject;
  3. import nuonuo.open.sdk.NNOpenSDK;
  4. import java.util.UUID;
  5. /**
  6. * 请求Api
  7. * <p>
  8. * 【这是一个Eclipse工程, JDK支持1.7+】
  9. */
  10. public class OpenApi {
  11. public static String appKey = "10509984";
  12. public static String taxnum = "339901999999500";
  13. public static String appSecret = "CAFB9D5A7E2141C3";
  14. public static String token = "370743d065d1e97e3c124315wjiqpvai";
  15. /**
  16. * 请求开放平台api
  17. * <p>
  18. * 请求地址, 详见 https://open.nuonuo.com/#/dev-doc/sdk-usage
  19. */
  20. public JSONObject requestApi(String method, String content) {
  21. // 参数配置
  22. // String taxnum = "339901999999821";//授权企业税号, 商户填""
  23. // String appKey = "SD79341075";
  24. // String appSecret = "SDAE0618F8514F14";
  25. // String method = "nuonuo.ElectronInvoice.requestBillingNew";
  26. // String token = "29a9a279edab1bb28e4cc40pigwd7sls";
  27. // String content = "填写API私有请求参数, 标准JSON格式";
  28. // String urhttps://www.chuanglan.com/control/loginl = "https://sdk.nuonuo.com/open/v1/services";// 票据识别请使用https://sdk.nuonuo.com/open/v2/ocr
  29. // String appSecret = "SDA63AFA88C6468C";
  30. //String url = "https://sandbox.nuonuocs.cn/open/v1/services";
  31. String url = "https://sdk.nuonuo.com/open/v1/services";
  32. String senid = UUID.randomUUID().toString().replace("-", ""); // 唯一标识,由企业自己生成32位随机码
  33. // 接口调用
  34. NNOpenSDK sdk = NNOpenSDK.getIntance();
  35. String json = sdk.sendPostSyncRequest(url, senid, appKey, appSecret, OpenToken.getMerchantToken(), taxnum, method, content);
  36. // 响应报文解析
  37. System.out.println("【API请求】");
  38. System.out.println(json);
  39. return JSONObject.fromObject(json);
  40. }
  41. }