ScanApi.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. #region Apache License Version 2.0
  2. /*----------------------------------------------------------------
  3. Copyright 2019 Jeffrey Su & Suzhou Senparc Network Technology Co.,Ltd.
  4. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
  5. except in compliance with the License. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software distributed under the
  8. License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  9. either express or implied. See the License for the specific language governing permissions
  10. and limitations under the License.
  11. Detail: https://github.com/JeffreySu/WeiXinMPSDK/blob/master/license.md
  12. ----------------------------------------------------------------*/
  13. #endregion Apache License Version 2.0
  14. /*----------------------------------------------------------------
  15. Copyright (C) 2019 Senparc
  16. 文件名:ScanApi.cs
  17. 文件功能描述:微信扫一扫
  18. 创建描述:增加获取商户信息接口,提交审核/取消发布商品接口,设置测试人员白名单接口,
  19. 批量查询商品信息接口,清除商品信息接口,检查wxticket参数接口
  20. 创建标识:Senparc - 20160520
  21. 修改标识:Senparc - 20160719
  22. 修改描述:增加其接口的异步方法
  23. 修改标识:Senparc - 20170707
  24. 修改描述:v14.5.1 完善异步方法async/await
  25. 修改标识:Senparc - 20170810
  26. 修改描述:v14.5.10 增加“获取商品二维码”接口(ScanApi.GetQrCode()),同时提供配套异步方法
  27. ----------------------------------------------------------------*/
  28. /*
  29. 官方文档:https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1419318587&lang=zh_CN
  30. */
  31. using System.Collections.Generic;
  32. using System.IO;
  33. using System.Threading.Tasks;
  34. using Senparc.CO2NET.Extensions;
  35. using Senparc.NeuChar;
  36. using Senparc.Weixin.CommonAPIs;
  37. using Senparc.Weixin.Entities;
  38. using Senparc.Weixin.Helpers;
  39. using Senparc.Weixin.HttpUtility;
  40. using Senparc.Weixin.MP.AdvancedAPIs.GroupMessage;
  41. using Senparc.Weixin.MP.AdvancedAPIs.Scan;
  42. using Senparc.Weixin.MP.CommonAPIs;
  43. namespace Senparc.Weixin.MP.AdvancedAPIs
  44. {
  45. /// <summary>
  46. /// 微信扫一扫接口
  47. /// </summary>
  48. public static class ScanApi
  49. {
  50. #region 同步方法
  51. /// <summary>
  52. /// 获取商户信息
  53. /// </summary>
  54. /// <param name="accessTokenOrAppId">AccessToken或AppId(推荐使用AppId,需要先注册)</param>
  55. /// <param name="timeOut"></param>
  56. /// <returns></returns>
  57. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ScanApi.MerchantInfoGet", true)]
  58. public static MerchantInfoGetResultJson MerchantInfoGet(string accessTokenOrAppId, int timeOut = Config.TIME_OUT)
  59. {
  60. return ApiHandlerWapper.TryCommonApi(accessToken =>
  61. {
  62. var urlFormat = string.Format(Config.ApiMpHost + "/scan/merchantinfo/get?access_token={0}", accessToken.AsUrlData());
  63. return CommonJsonSend.Send<MerchantInfoGetResultJson>(null, urlFormat, null, CommonJsonSendType.GET, timeOut: timeOut);
  64. }, accessTokenOrAppId);
  65. }
  66. /// <summary>
  67. /// 创建商品
  68. /// </summary>
  69. /// <param name="accessTokenOrAppId">AccessToken或AppId(推荐使用AppId,需要先注册)</param>
  70. /// <pram name="keyStandard">商品编码标准,暂时只支持ean13和ean8两种标准。</pram>
  71. /// <pram name="keyStr">商品编码内容。直接填写商品条码,如“6900000000000”;注意:编码标准是ean13时,编码内容必须在商户的号段之下,否则会报错。</pram>
  72. /// <pram name="baseInfo">商品的基本信息。</pram>
  73. /// <param name="timeOut"></param>
  74. /// <returns></returns>
  75. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ScanApi.ProductCreate", true)]
  76. public static ProductCreateResultJson ProductCreate(string accessTokenOrAppId, string keyStandard, string keyStr, BrandInfo brandInfo, int timeOut = Config.TIME_OUT)
  77. {
  78. return ApiHandlerWapper.TryCommonApi(accessToken =>
  79. {
  80. var urlFormat = string.Format(Config.ApiMpHost + "/scan/product/create?access_token={0}", accessToken.AsUrlData());
  81. var data = new
  82. {
  83. keystandard = keyStandard,
  84. keystr = keyStr,
  85. brand_info = brandInfo
  86. };
  87. return CommonJsonSend.Send<ProductCreateResultJson>(null, urlFormat, null, CommonJsonSendType.POST, timeOut: timeOut);
  88. }, accessTokenOrAppId);
  89. }
  90. /// <summary>
  91. ///提交审核/取消发布商品
  92. /// </summary>
  93. /// <param name="accessTokenOrAppId">AccessToken或AppId(推荐使用AppId,需要先注册)</param>
  94. /// <param name="keyStandard">商品编码标准。</param>
  95. /// <param name="keyStr">商品编码内容。</param>
  96. /// <param name="status">设置发布状态。on为提交审核,off为取消发布。</param>
  97. /// <param name="timeOut"></param>
  98. /// <returns></returns>
  99. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ScanApi.ModStatus", true)]
  100. public static WxJsonResult ModStatus(string accessTokenOrAppId, string keyStandard, string keyStr, string status, int timeOut = Config.TIME_OUT)
  101. {
  102. return ApiHandlerWapper.TryCommonApi(accessToken =>
  103. {
  104. var urlFormat = string.Format(Config.ApiMpHost + "/scan/product/modstatus?access_token={0}", accessToken.AsUrlData());
  105. var data = new
  106. {
  107. keystandard = keyStandard,
  108. keystr = keyStr,
  109. status = status
  110. };
  111. return CommonJsonSend.Send<WxJsonResult>(null, urlFormat, data, CommonJsonSendType.POST, timeOut: timeOut);
  112. }, accessTokenOrAppId);
  113. }
  114. /// <summary>
  115. ///设置测试人员白名单
  116. /// </summary>
  117. /// <param name="accessTokenOrAppId">AccessToken或AppId(推荐使用AppId,需要先注册)</param>
  118. /// <param name="openId">测试人员的openid列表。</param>
  119. /// <param name="userName">测试人员的微信号列表。</param>
  120. /// <param name="timeOut"></param>
  121. /// <returns></returns>
  122. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ScanApi.TestWhiteListSet", true)]
  123. public static WxJsonResult TestWhiteListSet(string accessTokenOrAppId, string openId, string userName, int timeOut = Config.TIME_OUT)
  124. {
  125. return ApiHandlerWapper.TryCommonApi(accessToken =>
  126. {
  127. var urlFormat = string.Format(Config.ApiMpHost + "/scan/testwhitelist/set?access_token={0}", accessToken.AsUrlData());
  128. var data = new
  129. {
  130. openid = openId,
  131. userName = userName
  132. };
  133. return CommonJsonSend.Send<WxJsonResult>(null, urlFormat, data, CommonJsonSendType.POST, timeOut: timeOut);
  134. }, accessTokenOrAppId);
  135. }
  136. /*
  137. /// <summary>
  138. ///查询商品信息
  139. /// </summary>
  140. /// <param name="accessTokenOrAppId">AccessToken或AppId(推荐使用AppId,需要先注册)</param>
  141. /// <param name="keyStandard">商品编码标准。</param>
  142. /// <param name="keyStr">商品编码内容。</param>
  143. /// <param name="timeOut"></param>
  144. /// <returns></returns>
  145. public static ProductGetJsonResult ProductGet(string accessTokenOrAppId, string keyStandard, string keyStr, int timeOut = Config.TIME_OUT)
  146. {
  147. return ApiHandlerWapper.TryCommonApi(accessToken =>
  148. {
  149. var urlFormat = string.Format(Config.ApiMpHost + "/scan/product/get?access_token={0}", accessToken.AsUrlData());
  150. var data = new
  151. {
  152. keystandard = keyStandard,
  153. keystr = keyStr
  154. };
  155. return CommonJsonSend.Send<ProductGetJsonResult>(null, urlFormat, data, CommonJsonSendType.POST, timeOut: timeOut);
  156. }, accessTokenOrAppId);
  157. }*/
  158. /// <summary>
  159. ///批量查询商品信息
  160. /// </summary>
  161. /// <param name="accessTokenOrAppId">AccessToken或AppId(推荐使用AppId,需要先注册)</param>
  162. /// <param name="offset">商品编码标准。</param>
  163. /// <param name="limit">商品编码标准。</param>
  164. /// <param name="status">商品编码内容。</param>
  165. /// <param name="timeOut"></param>
  166. /// <returns></returns>
  167. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ScanApi.ProductGetList", true)]
  168. public static ProductGetListJsonResult ProductGetList(string accessTokenOrAppId, int offset, int limit, string status, int timeOut = Config.TIME_OUT)
  169. {
  170. return ApiHandlerWapper.TryCommonApi(accessToken =>
  171. {
  172. var urlFormat = string.Format(Config.ApiMpHost + "/scan/product/getlist?access_token={0}", accessToken.AsUrlData());
  173. var data = new
  174. {
  175. offset = offset,
  176. limit = limit,
  177. status = status
  178. };
  179. return CommonJsonSend.Send<ProductGetListJsonResult>(null, urlFormat, data, CommonJsonSendType.POST, timeOut: timeOut);
  180. }, accessTokenOrAppId);
  181. }
  182. /// <summary>
  183. ///清除商品信息
  184. /// </summary>
  185. /// <param name="accessTokenOrAppId">AccessToken或AppId(推荐使用AppId,需要先注册)</param>
  186. /// <param name="keyStandard">商品编码标准。</param>
  187. /// <param name="keyStr">商品编码标准。</param>
  188. /// <param name="timeOut"></param>
  189. /// <returns></returns>
  190. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ScanApi.ProductClear", true)]
  191. public static WxJsonResult ProductClear(string accessTokenOrAppId, int keyStandard, string keyStr, int timeOut = Config.TIME_OUT)
  192. {
  193. return ApiHandlerWapper.TryCommonApi(accessToken =>
  194. {
  195. var urlFormat = string.Format(Config.ApiMpHost + "/scan/product/clear?access_token={0}", accessToken.AsUrlData());
  196. var data = new
  197. {
  198. keystandard = keyStandard,
  199. keystr = keyStr
  200. };
  201. return CommonJsonSend.Send<WxJsonResult>(null, urlFormat, data, CommonJsonSendType.POST, timeOut: timeOut);
  202. }, accessTokenOrAppId);
  203. }
  204. /// <summary>
  205. ///检查wxticket参数
  206. /// </summary>
  207. /// <param name="accessTokenOrAppId">AccessToken或AppId(推荐使用AppId,需要先注册)</param>
  208. /// <param name="ticket">请求URL中带上的wxticket参数。</param>
  209. /// <param name="timeOut"></param>
  210. /// <returns></returns>
  211. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ScanApi.ScanTicketCheck", true)]
  212. public static ScanTicketCheckJsonResult ScanTicketCheck(string accessTokenOrAppId, string ticket, int timeOut = Config.TIME_OUT)
  213. {
  214. return ApiHandlerWapper.TryCommonApi(accessToken =>
  215. {
  216. var urlFormat = string.Format(Config.ApiMpHost + "/scan/scanticket/check?access_token={0}", accessToken.AsUrlData());
  217. var data = new
  218. {
  219. ticket = ticket
  220. };
  221. return CommonJsonSend.Send<ScanTicketCheckJsonResult>(null, urlFormat, data, CommonJsonSendType.POST, timeOut: timeOut);
  222. }, accessTokenOrAppId);
  223. }
  224. /// <summary>
  225. /// 获取商品二维码
  226. /// 官方文档地址:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1455872062
  227. /// </summary>
  228. /// <param name="accessTokenOrAppId">AccessToken或AppId(推荐使用AppId,需要先注册)</param>
  229. /// <param name="keystr">商品编码内容</param>
  230. /// <param name="extinfo">(非必填)由商户自定义传入,建议仅使用大小写字母、数字及-_().*这6个常用字符</param>
  231. /// <param name="keystandard">商品编码标准</param>
  232. /// <param name="qrcode_size">二维码的尺寸(整型),数值代表边长像素数,默认为100</param>
  233. /// <param name="timeOut"></param>
  234. /// <returns></returns>
  235. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ScanApi.GetQrCode", true)]
  236. public static ProductGetQrCodeJsonResult GetQrCode(string accessTokenOrAppId, string keystr, string extinfo = null, string keystandard = "ean13", int qrcode_size = 100, int timeOut = Config.TIME_OUT)
  237. {
  238. return ApiHandlerWapper.TryCommonApi(accessToken =>
  239. {
  240. var urlFormat = string.Format(Config.ApiMpHost + "/scan/product/getqrcode?access_token={0}", accessToken.AsUrlData());
  241. var data = new
  242. {
  243. keystandard,
  244. keystr,
  245. extinfo,
  246. qrcode_size
  247. };
  248. return CommonJsonSend.Send<ProductGetQrCodeJsonResult>(null, urlFormat, data, CommonJsonSendType.POST, timeOut: timeOut);
  249. }, accessTokenOrAppId);
  250. }
  251. /// <summary>
  252. /// 更新商品信息
  253. /// </summary>
  254. /// <param name="accessTokenOrAppId"></param>
  255. /// <param name="data"></param>
  256. /// <param name="timeOut"></param>
  257. /// <returns></returns>
  258. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ScanApi.UpdateBrand", true)]
  259. public static UpdateBrandResultJson UpdateBrand(string accessTokenOrAppId, UpdateBrandData data, int timeOut = Config.TIME_OUT)
  260. {
  261. return ApiHandlerWapper.TryCommonApi(accessToken =>
  262. {
  263. var urlFormat = string.Format(Config.ApiMpHost + "/scan/product/update?access_token={0}", accessToken.AsUrlData());
  264. return CommonJsonSend.Send<UpdateBrandResultJson>(null, urlFormat, data, CommonJsonSendType.POST, timeOut: timeOut);
  265. }, accessTokenOrAppId);
  266. }
  267. #endregion
  268. #if !NET35 && !NET40
  269. #region 异步方法
  270. /// <summary>
  271. /// 【异步方法】获取商户信息
  272. /// </summary>
  273. /// <param name="accessTokenOrAppId">AccessToken或AppId(推荐使用AppId,需要先注册)</param>
  274. /// <param name="timeOut"></param>
  275. /// <returns></returns>
  276. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ScanApi.MerchantInfoGetAsync", true)]
  277. public static async Task<MerchantInfoGetResultJson> MerchantInfoGetAsync(string accessTokenOrAppId, int timeOut = Config.TIME_OUT)
  278. {
  279. return await ApiHandlerWapper.TryCommonApiAsync(async accessToken =>
  280. {
  281. var urlFormat = string.Format(Config.ApiMpHost + "/scan/merchantinfo/get?access_token={0}", accessToken.AsUrlData());
  282. return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<MerchantInfoGetResultJson>(null, urlFormat, null, CommonJsonSendType.GET, timeOut: timeOut);
  283. }, accessTokenOrAppId);
  284. }
  285. /// <summary>
  286. /// 【异步方法】创建商品
  287. /// </summary>
  288. /// <param name="accessTokenOrAppId">AccessToken或AppId(推荐使用AppId,需要先注册)</param>
  289. /// <pram name="keyStandard">商品编码标准,暂时只支持ean13和ean8两种标准。</pram>
  290. /// <pram name="keyStr">商品编码内容。直接填写商品条码,如“6900000000000”;注意:编码标准是ean13时,编码内容必须在商户的号段之下,否则会报错。</pram>
  291. /// <pram name="baseInfo">商品的基本信息。</pram>
  292. /// <param name="timeOut"></param>
  293. /// <returns></returns>
  294. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ScanApi.ProductCreateAsync", true)]
  295. public static async Task<ProductCreateResultJson> ProductCreateAsync(string accessTokenOrAppId, string keyStandard, string keyStr, BrandInfo brandInfo, int timeOut = Config.TIME_OUT)
  296. {
  297. return await ApiHandlerWapper.TryCommonApiAsync(async accessToken =>
  298. {
  299. var urlFormat = string.Format(Config.ApiMpHost + "/scan/product/create?access_token={0}", accessToken.AsUrlData());
  300. var data = new
  301. {
  302. keystandard = keyStandard,
  303. keystr = keyStr,
  304. brand_info = brandInfo
  305. };
  306. return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<ProductCreateResultJson>(null, urlFormat, null, CommonJsonSendType.POST, timeOut: timeOut);
  307. }, accessTokenOrAppId);
  308. }
  309. /// <summary>
  310. ///【异步方法】提交审核/取消发布商品
  311. /// </summary>
  312. /// <param name="accessTokenOrAppId">AccessToken或AppId(推荐使用AppId,需要先注册)</param>
  313. /// <param name="keyStandard">商品编码标准。</param>
  314. /// <param name="keyStr">商品编码内容。</param>
  315. /// <param name="status">设置发布状态。on为提交审核,off为取消发布。</param>
  316. /// <param name="timeOut"></param>
  317. /// <returns></returns>
  318. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ScanApi.ModStatusAsync", true)]
  319. public static async Task<WxJsonResult> ModStatusAsync(string accessTokenOrAppId, string keyStandard, string keyStr, string status, int timeOut = Config.TIME_OUT)
  320. {
  321. return await ApiHandlerWapper.TryCommonApiAsync(async accessToken =>
  322. {
  323. var urlFormat = string.Format(Config.ApiMpHost + "/scan/product/modstatus?access_token={0}", accessToken.AsUrlData());
  324. var data = new
  325. {
  326. keystandard = keyStandard,
  327. keystr = keyStr,
  328. status = status
  329. };
  330. return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<WxJsonResult>(null, urlFormat, data, CommonJsonSendType.POST, timeOut: timeOut);
  331. }, accessTokenOrAppId);
  332. }
  333. /// <summary>
  334. ///【异步方法】设置测试人员白名单
  335. /// </summary>
  336. /// <param name="accessTokenOrAppId">AccessToken或AppId(推荐使用AppId,需要先注册)</param>
  337. /// <param name="openId">测试人员的openid列表。</param>
  338. /// <param name="userName">测试人员的微信号列表。</param>
  339. /// <param name="timeOut"></param>
  340. /// <returns></returns>
  341. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ScanApi.TestWhiteListSetAsync", true)]
  342. public static async Task<WxJsonResult> TestWhiteListSetAsync(string accessTokenOrAppId, string openId, string userName, int timeOut = Config.TIME_OUT)
  343. {
  344. return await ApiHandlerWapper.TryCommonApiAsync(async accessToken =>
  345. {
  346. var urlFormat = string.Format(Config.ApiMpHost + "/scan/testwhitelist/set?access_token={0}", accessToken.AsUrlData());
  347. var data = new
  348. {
  349. openid = openId,
  350. userName = userName
  351. };
  352. return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<WxJsonResult>(null, urlFormat, data, CommonJsonSendType.POST, timeOut: timeOut);
  353. }, accessTokenOrAppId);
  354. }
  355. /*
  356. /// <summary>
  357. ///【异步方法】查询商品信息
  358. /// </summary>
  359. /// <param name="accessTokenOrAppId">AccessToken或AppId(推荐使用AppId,需要先注册)</param>
  360. /// <param name="keyStandard">商品编码标准。</param>
  361. /// <param name="keyStr">商品编码内容。</param>
  362. /// <param name="timeOut"></param>
  363. /// <returns></returns>
  364. public static ProductGetJsonResult ProductGet(string accessTokenOrAppId, string keyStandard, string keyStr, int timeOut = Config.TIME_OUT)
  365. {
  366. return ApiHandlerWapper.TryCommonApi(accessToken =>
  367. {
  368. var urlFormat = string.Format(Config.ApiMpHost + "/scan/product/get?access_token={0}", accessToken.AsUrlData());
  369. var data = new
  370. {
  371. keystandard = keyStandard,
  372. keystr = keyStr
  373. };
  374. return CommonJsonSend.Send<ProductGetJsonResult>(null, urlFormat, data, CommonJsonSendType.POST, timeOut: timeOut);
  375. }, accessTokenOrAppId);
  376. }*/
  377. /// <summary>
  378. ///【异步方法】批量查询商品信息
  379. /// </summary>
  380. /// <param name="accessTokenOrAppId">AccessToken或AppId(推荐使用AppId,需要先注册)</param>
  381. /// <param name="offset">商品编码标准。</param>
  382. /// <param name="limit">商品编码标准。</param>
  383. /// <param name="status">商品编码内容。</param>
  384. /// <param name="timeOut"></param>
  385. /// <returns></returns>
  386. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ScanApi.ProductGetListAsync", true)]
  387. public static async Task<ProductGetListJsonResult> ProductGetListAsync(string accessTokenOrAppId, int offset, int limit, string status, int timeOut = Config.TIME_OUT)
  388. {
  389. return await ApiHandlerWapper.TryCommonApiAsync(async accessToken =>
  390. {
  391. var urlFormat = string.Format(Config.ApiMpHost + "/scan/product/getlist?access_token={0}", accessToken.AsUrlData());
  392. var data = new
  393. {
  394. offset = offset,
  395. limit = limit,
  396. status = status
  397. };
  398. return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<ProductGetListJsonResult>(null, urlFormat, data, CommonJsonSendType.POST, timeOut: timeOut);
  399. }, accessTokenOrAppId);
  400. }
  401. /// <summary>
  402. ///【异步方法】清除商品信息
  403. /// </summary>
  404. /// <param name="accessTokenOrAppId">AccessToken或AppId(推荐使用AppId,需要先注册)</param>
  405. /// <param name="keyStandard">商品编码标准。</param>
  406. /// <param name="keyStr">商品编码标准。</param>
  407. /// <param name="timeOut"></param>
  408. /// <returns></returns>
  409. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ScanApi.ProductClearAsync", true)]
  410. public static async Task<WxJsonResult> ProductClearAsync(string accessTokenOrAppId, int keyStandard, string keyStr, int timeOut = Config.TIME_OUT)
  411. {
  412. return await ApiHandlerWapper.TryCommonApiAsync(async accessToken =>
  413. {
  414. var urlFormat = string.Format(Config.ApiMpHost + "/scan/product/clear?access_token={0}", accessToken.AsUrlData());
  415. var data = new
  416. {
  417. keystandard = keyStandard,
  418. keystr = keyStr
  419. };
  420. return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<WxJsonResult>(null, urlFormat, data, CommonJsonSendType.POST, timeOut: timeOut);
  421. }, accessTokenOrAppId);
  422. }
  423. /// <summary>
  424. ///【异步方法】检查wxticket参数
  425. /// </summary>
  426. /// <param name="accessTokenOrAppId">AccessToken或AppId(推荐使用AppId,需要先注册)</param>
  427. /// <param name="ticket">请求URL中带上的wxticket参数。</param>
  428. /// <param name="timeOut"></param>
  429. /// <returns></returns>
  430. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ScanApi.ScanTicketCheckAsync", true)]
  431. public static async Task<ScanTicketCheckJsonResult> ScanTicketCheckAsync(string accessTokenOrAppId, string ticket, int timeOut = Config.TIME_OUT)
  432. {
  433. return await ApiHandlerWapper.TryCommonApiAsync(async accessToken =>
  434. {
  435. var urlFormat = string.Format(Config.ApiMpHost + "/scan/scanticket/check?access_token={0}", accessToken.AsUrlData());
  436. var data = new
  437. {
  438. ticket = ticket
  439. };
  440. return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<ScanTicketCheckJsonResult>(null, urlFormat, data, CommonJsonSendType.POST, timeOut: timeOut);
  441. }, accessTokenOrAppId);
  442. }
  443. /// <summary>
  444. /// 【异步方法】获取商品二维码
  445. /// 官方文档地址:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1455872062
  446. /// </summary>
  447. /// <param name="accessTokenOrAppId">AccessToken或AppId(推荐使用AppId,需要先注册)</param>
  448. /// <param name="keystr">商品编码内容</param>
  449. /// <param name="extinfo">(非必填)由商户自定义传入,建议仅使用大小写字母、数字及-_().*这6个常用字符</param>
  450. /// <param name="keystandard">商品编码标准</param>
  451. /// <param name="qrcode_size">二维码的尺寸(整型),数值代表边长像素数,默认为100</param>
  452. /// <param name="timeOut"></param>
  453. /// <returns></returns>
  454. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ScanApi.GetQrCodeAsync", true)]
  455. public static async Task<ProductGetQrCodeJsonResult> GetQrCodeAsync(string accessTokenOrAppId, string keystr, string extinfo = null, string keystandard = "ean13", int qrcode_size = 100, int timeOut = Config.TIME_OUT)
  456. {
  457. return await ApiHandlerWapper.TryCommonApiAsync(async accessToken =>
  458. {
  459. var urlFormat = string.Format(Config.ApiMpHost + "/scan/product/getqrcode?access_token={0}", accessToken.AsUrlData());
  460. var data = new
  461. {
  462. keystandard,
  463. keystr,
  464. extinfo,
  465. qrcode_size
  466. };
  467. return await Senparc.Weixin.CommonAPIs.CommonJsonSend.SendAsync<ProductGetQrCodeJsonResult>(null, urlFormat, data, CommonJsonSendType.POST, timeOut: timeOut);
  468. }, accessTokenOrAppId);
  469. }
  470. /// <summary>
  471. /// 【异步方法】更新商品信息
  472. /// </summary>
  473. /// <param name="accessTokenOrAppId"></param>
  474. /// <param name="data"></param>
  475. /// <param name="timeOut"></param>
  476. /// <returns></returns>
  477. [ApiBind(NeuChar.PlatformType.WeChat_OfficialAccount, "ScanApi.UpdateBrandAsync", true)]
  478. public static async Task<UpdateBrandResultJson> UpdateBrandAsync(string accessTokenOrAppId, UpdateBrandData data, int timeOut = Config.TIME_OUT)
  479. {
  480. return await ApiHandlerWapper.TryCommonApiAsync(async accessToken =>
  481. {
  482. var urlFormat = string.Format(Config.ApiMpHost + "/scan/product/update?access_token={0}", accessToken.AsUrlData());
  483. return await Weixin.CommonAPIs.CommonJsonSend.SendAsync<UpdateBrandResultJson>(null, urlFormat, data, CommonJsonSendType.POST, timeOut: timeOut);
  484. }, accessTokenOrAppId);
  485. }
  486. #endregion
  487. #endif
  488. }
  489. }