V2TradePaymentJspayRequestDemo.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. using System;
  2. using System.Collections.Generic;
  3. using BasePaySdk;
  4. using BasePaySdk.Request;
  5. using Newtonsoft.Json;
  6. using Newtonsoft.Json.Linq;
  7. namespace BasePayDemo
  8. {
  9. /**
  10. * 聚合正扫接口 - 示例
  11. *
  12. * @author sdk-generator
  13. * @Description
  14. */
  15. public class V2TradePaymentJspayRequestDemo
  16. {
  17. public static void V2TradePaymentJspayRequestDemoTest()
  18. {
  19. // 1. 数据初始化
  20. InitMerConfig.init();
  21. // 2.组装请求参数
  22. V2TradePaymentJspayRequest request = new V2TradePaymentJspayRequest();
  23. // 请求日期
  24. request.setReqDate(DateTime.Now.ToString("yyyyMMdd"));
  25. // 请求流水号
  26. request.setReqSeqId(DateTime.Now.ToString("yyy-MM-dd HH.mm.ss.fff"));
  27. // 商户号
  28. request.setHuifuId("6666000109133323");
  29. // 商品描述
  30. request.setGoodsDesc("hibs自动化-通用版验证");
  31. // 交易类型
  32. request.setTradeType("A_NATIVE");
  33. // 交易金额
  34. request.setTransAmt("0.10");
  35. // 设置非必填字段
  36. Dictionary<string, object> extendInfoMap = getExtendInfos();
  37. request.setExtendInfo(extendInfoMap);
  38. try {
  39. // 3. 发起API调用
  40. // 调用接口,使用默认商户配置时可省略配置key
  41. Dictionary<string, Object> result = null;
  42. result = BasePayClient.postRequest(request,null);
  43. // 使用指定配置调用接口
  44. // result = BasePayClient.postRequest(request,null,"merchantKey2");
  45. Console.WriteLine(JsonConvert.SerializeObject(result));
  46. }
  47. catch (Exception ex) {
  48. Console.WriteLine(ex);
  49. }
  50. }
  51. /**
  52. * 非必填字段
  53. * @return
  54. */
  55. private static Dictionary<string, object> getExtendInfos() {
  56. // 设置非必填字段
  57. Dictionary<string, object> extendInfoMap = new Dictionary<string, object>();
  58. // 账户号
  59. // extendInfoMap.Add("acct_id", "");
  60. // 交易有效期
  61. extendInfoMap.Add("time_expire", "20250518235959");
  62. // 微信参数集合
  63. extendInfoMap.Add("wx_data", getWxData());
  64. // 支付宝参数集合
  65. extendInfoMap.Add("alipay_data", getAlipayData());
  66. // 银联参数集合
  67. extendInfoMap.Add("unionpay_data", getUnionpayData());
  68. // 数字人民币参数集合
  69. // extendInfoMap.Add("dc_data", getDcData());
  70. // 是否延迟交易
  71. extendInfoMap.Add("delay_acct_flag", "N");
  72. // 手续费扣款标志
  73. // extendInfoMap.Add("fee_flag", "");
  74. // 分账对象
  75. extendInfoMap.Add("acct_split_bunch", getAcctSplitBunch());
  76. // 传入分账遇到优惠的处理规则
  77. extendInfoMap.Add("term_div_coupon_type", "0");
  78. // 补贴支付信息
  79. // extendInfoMap.Add("combinedpay_data", getCombinedpayData());
  80. // 禁用信用卡标记
  81. extendInfoMap.Add("limit_pay_type", "NO_CREDIT");
  82. // 商户贴息标记
  83. extendInfoMap.Add("fq_mer_discount_flag", "N");
  84. // 渠道号
  85. extendInfoMap.Add("channel_no", "");
  86. // 场景类型
  87. extendInfoMap.Add("pay_scene", "02");
  88. // 备注
  89. extendInfoMap.Add("remark", "string");
  90. // 安全信息
  91. extendInfoMap.Add("risk_check_data", getRiskCheckData());
  92. // 设备信息
  93. extendInfoMap.Add("terminal_device_data", getTerminalDeviceData());
  94. // 异步通知地址
  95. extendInfoMap.Add("notify_url", "http://www.baidu.com");
  96. return extendInfoMap;
  97. }
  98. private static object getGoodsDetailWxRucan() {
  99. Dictionary<string, object> obj = new Dictionary<string, object>();
  100. // 商品编码
  101. obj.Add("goods_id", "6934572310301");
  102. // 商品名称
  103. obj.Add("goods_name", "太龙双黄连口服液");
  104. // 商品单价(元)
  105. obj.Add("price", "43.00");
  106. // 商品数量
  107. obj.Add("quantity", "1");
  108. // 微信侧商品编码
  109. obj.Add("wxpay_goods_id", "12235413214070356458058");
  110. JArray objList = new JArray();
  111. objList.Add(JToken.FromObject(obj));
  112. return objList;
  113. }
  114. private static object getDetail() {
  115. Dictionary<string, object> obj = new Dictionary<string, object>();
  116. // 单品列表
  117. obj.Add("goods_detail", getGoodsDetailWxRucan());
  118. // 订单原价(元)
  119. obj.Add("cost_price", "43.00");
  120. // 商品小票ID
  121. obj.Add("receipt_id", "20220628132043853798");
  122. return obj;
  123. }
  124. private static object getStoreInfo() {
  125. Dictionary<string, object> obj = new Dictionary<string, object>();
  126. // 门店id
  127. // obj.Add("id", "");
  128. // 门店名称
  129. // obj.Add("name", "");
  130. // 门店行政区划码
  131. // obj.Add("area_code", "");
  132. // 门店详细地址
  133. // obj.Add("ass", "");
  134. return obj;
  135. }
  136. private static object getSceneInfo() {
  137. Dictionary<string, object> obj = new Dictionary<string, object>();
  138. // 门店信息
  139. // obj.Add("store_info", getStoreInfo());
  140. return obj;
  141. }
  142. private static string getWxData() {
  143. Dictionary<string, object> obj = new Dictionary<string, object>();
  144. // 子商户应用ID
  145. obj.Add("sub_appid", "wxdfe9a5d141f96685");
  146. // 子商户用户标识
  147. obj.Add("sub_openid", "o8jhotzittQSetZ-N0Yj4Hz91Rqc");
  148. // 附加数据
  149. // obj.Add("attach", "");
  150. // 商品描述
  151. // obj.Add("body", "");
  152. // 商品详情
  153. obj.Add("detail", getDetail());
  154. // 设备号
  155. // obj.Add("device_info", "");
  156. // 订单优惠标记
  157. // obj.Add("goods_tag", "");
  158. // 实名支付
  159. // obj.Add("identity", "");
  160. // 开发票入口开放标识
  161. // obj.Add("receipt", "");
  162. // 场景信息
  163. obj.Add("scene_info", getSceneInfo());
  164. // 终端ip
  165. // obj.Add("spbill_create_ip", "");
  166. // 单品优惠标识
  167. // obj.Add("promotion_flag", "");
  168. // 新增商品ID
  169. // obj.Add("product_id", "");
  170. // 指定支付者
  171. // obj.Add("limit_payer", "");
  172. return JsonConvert.SerializeObject(obj);
  173. }
  174. private static object getExtendParams() {
  175. Dictionary<string, object> obj = new Dictionary<string, object>();
  176. // 卡类型
  177. obj.Add("card_type", "");
  178. // 支付宝点餐场景类型
  179. obj.Add("food_order_type", "qr_order");
  180. // 花呗分期数
  181. obj.Add("hb_fq_num", "");
  182. // 花呗卖家手续费百分比
  183. obj.Add("hb_fq_seller_percent", "");
  184. // 行业数据回流信息
  185. obj.Add("industry_reflux_info", "string");
  186. // 信用卡分期资产方式
  187. // obj.Add("fq_channels", "");
  188. // 停车场id
  189. obj.Add("parking_id", "123wsx");
  190. // 系统商编号
  191. obj.Add("sys_service_provider_id", "1111111");
  192. return obj;
  193. }
  194. private static object getGoodsDetail() {
  195. Dictionary<string, object> obj = new Dictionary<string, object>();
  196. // 商品的编号
  197. obj.Add("goods_id", "12312321");
  198. // 商品名称
  199. obj.Add("goods_name", "汇付");
  200. // 商品单价(元)
  201. obj.Add("price", "43.00");
  202. // 商品数量
  203. obj.Add("quantity", "20");
  204. // 商品描述信息
  205. obj.Add("body", "");
  206. // 商品类目树
  207. obj.Add("categories_tree", "string");
  208. // 商品类目
  209. obj.Add("goods_category", "");
  210. // 商品的展示地址
  211. obj.Add("show_url", "");
  212. JArray objList = new JArray();
  213. objList.Add(JToken.FromObject(obj));
  214. return objList;
  215. }
  216. private static object getExtUserInfo() {
  217. Dictionary<string, object> obj = new Dictionary<string, object>();
  218. // 姓名
  219. // obj.Add("name", "");
  220. // 手机号
  221. // obj.Add("mobile", "");
  222. // 证件类型
  223. // obj.Add("cert_type", "");
  224. // 证件号
  225. // obj.Add("cert_no", "");
  226. // 允许的最小买家年龄
  227. // obj.Add("min_age", "");
  228. // 是否强制校验付款人身份信息
  229. // obj.Add("fix_buyer", "");
  230. // 是否强制校验身份信息
  231. // obj.Add("need_check_info", "");
  232. return obj;
  233. }
  234. private static string getAlipayData() {
  235. Dictionary<string, object> obj = new Dictionary<string, object>();
  236. // 买家的支付宝唯一用户号
  237. obj.Add("buyer_id", "2088702699908257");
  238. // 支付宝的店铺编号
  239. obj.Add("alipay_store_id", "");
  240. // 买家支付宝账号
  241. obj.Add("buyer_logon_id", "string");
  242. // 业务扩展参数
  243. obj.Add("extend_params", getExtendParams());
  244. // 订单包含的商品列表信息
  245. obj.Add("goods_detail", getGoodsDetail());
  246. // 商户原始订单号
  247. obj.Add("merchant_order_no", "string");
  248. // 商户操作员编号
  249. obj.Add("operator_id", "123213213");
  250. // 销售产品码
  251. obj.Add("product_code", "string");
  252. // 卖家支付宝用户号
  253. obj.Add("seller_id", "string");
  254. // 商户门店编号
  255. obj.Add("store_id", "");
  256. // 外部指定买家
  257. // obj.Add("ext_user_info", getExtUserInfo());
  258. // 订单标题
  259. // obj.Add("subject", "");
  260. // 商家门店名称
  261. // obj.Add("store_name", "");
  262. // 小程序应用的appid
  263. // obj.Add("op_app_id", "");
  264. // 商户业务信息
  265. // obj.Add("ali_business_params", "");
  266. return JsonConvert.SerializeObject(obj);
  267. }
  268. private static object getPayeeInfo() {
  269. Dictionary<string, object> obj = new Dictionary<string, object>();
  270. // 商户类别
  271. // obj.Add("mer_cat_code", "");
  272. // 二级商户代码
  273. // obj.Add("sub_id", "");
  274. // 二级商户名称
  275. // obj.Add("sub_name", "");
  276. // 终端号
  277. // obj.Add("term_id", "");
  278. return obj;
  279. }
  280. private static string getUnionpayData() {
  281. Dictionary<string, object> obj = new Dictionary<string, object>();
  282. // 二维码
  283. // obj.Add("qr_code", "");
  284. // 收款方附加数据
  285. // obj.Add("addn_data", "");
  286. // 地区信息
  287. // obj.Add("area_info", "");
  288. // 持卡人ip
  289. // obj.Add("customer_ip", "");
  290. // 前台通知地址
  291. // obj.Add("front_url", "");
  292. // 订单描述
  293. // obj.Add("order_desc", "");
  294. // 收款方附言
  295. // obj.Add("payee_comments", "");
  296. // 收款方信息
  297. // obj.Add("payee_info", getPayeeInfo());
  298. // 银联分配的服务商机构标识码
  299. // obj.Add("pnr_ins_id_cd", "");
  300. // 请求方自定义域
  301. // obj.Add("req_reserved", "");
  302. // 终端信息
  303. // obj.Add("term_info", "");
  304. // 银联用户标识
  305. // obj.Add("user_id", "");
  306. return JsonConvert.SerializeObject(obj);
  307. }
  308. private static string getDcData() {
  309. Dictionary<string, object> obj = new Dictionary<string, object>();
  310. // 数字货币银行编号
  311. // obj.Add("digital_bank_no", "");
  312. return JsonConvert.SerializeObject(obj);
  313. }
  314. private static object getAcctInfosRucan() {
  315. Dictionary<string, object> obj = new Dictionary<string, object>();
  316. // 分账接收方ID
  317. obj.Add("huifu_id", "6666000109133323");
  318. // 分账金额
  319. obj.Add("div_amt", "0.10");
  320. // 账户号
  321. // obj.Add("acct_id", "");
  322. // 分账百分比%
  323. // obj.Add("percentage_div", "");
  324. JArray objList = new JArray();
  325. objList.Add(JToken.FromObject(obj));
  326. return objList;
  327. }
  328. private static string getAcctSplitBunch() {
  329. Dictionary<string, object> obj = new Dictionary<string, object>();
  330. // 分账明细
  331. obj.Add("acct_infos", getAcctInfosRucan());
  332. // 百分比分账标志
  333. // obj.Add("percentage_flag", "");
  334. // 是否净值分账
  335. // obj.Add("is_clean_split", "");
  336. return JsonConvert.SerializeObject(obj);
  337. }
  338. private static string getCombinedpayData() {
  339. Dictionary<string, object> obj = new Dictionary<string, object>();
  340. // 补贴方汇付商户号
  341. // obj.Add("huifu_id", "test");
  342. // 补贴方类型
  343. // obj.Add("user_type", "test");
  344. // 补贴方账户号
  345. // obj.Add("acct_id", "test");
  346. // 补贴金额
  347. // obj.Add("amount", "test");
  348. JArray objList = new JArray();
  349. objList.Add(JToken.FromObject(obj));
  350. return JsonConvert.SerializeObject(objList);
  351. }
  352. private static string getRiskCheckData() {
  353. Dictionary<string, object> obj = new Dictionary<string, object>();
  354. // ip地址
  355. obj.Add("ip_addr", "180.167.105.130");
  356. // 基站地址
  357. obj.Add("base_station", "192.168.1.1");
  358. // 纬度
  359. obj.Add("latitude", "33.3");
  360. // 经度
  361. obj.Add("longitude", "33.3");
  362. return JsonConvert.SerializeObject(obj);
  363. }
  364. private static string getTerminalDeviceData() {
  365. Dictionary<string, object> obj = new Dictionary<string, object>();
  366. // 商户设备类型
  367. // obj.Add("mer_device_type", "test");
  368. // 汇付机具号
  369. obj.Add("devs_id", "SPINTP357338300264411");
  370. // 设备类型
  371. obj.Add("device_type", "1");
  372. // 交易设备IP
  373. obj.Add("device_ip", "10.10.0.1");
  374. // 交易设备MAC
  375. obj.Add("device_mac", "");
  376. // 交易设备IMEI
  377. obj.Add("device_imei", "");
  378. // 交易设备IMSI
  379. obj.Add("device_imsi", "");
  380. // 交易设备ICCID
  381. obj.Add("device_icc_id", "");
  382. // 交易设备WIFIMAC
  383. obj.Add("device_wifi_mac", "");
  384. // 交易设备GPS
  385. obj.Add("device_gps", "192.168.0.0");
  386. // 商户终端应用程序版本
  387. // obj.Add("app_version", "");
  388. // SIM 卡卡号
  389. // obj.Add("icc_id", "");
  390. // 商户终端实时经纬度信息
  391. // obj.Add("location", "");
  392. // 商户交易设备IP
  393. // obj.Add("mer_device_ip", "");
  394. // 移动国家代码
  395. // obj.Add("mobile_country_cd", "");
  396. // 移动网络号码
  397. // obj.Add("mobile_net_num", "");
  398. // 商户终端入网认证编号
  399. // obj.Add("network_license", "");
  400. // 商户终端序列号
  401. // obj.Add("serial_num", "");
  402. return JsonConvert.SerializeObject(obj);
  403. }
  404. }
  405. }