小程序发送红包,一直出现 参数错误:send_name字段必填,并且少于32字符
给个人发红包,总是出现 [代码]<[代码][代码]xml[代码][代码]><[代码][代码]return_code[代码][代码]>[代码][代码]<![CDATA[SUCCESS]]>[代码][代码]</[代码][代码]return_code[代码][代码]><[代码][代码]return_msg[代码][代码]>[代码][代码]<![CDATA[参数错误:send_name字段必填,并且少于32字符]]>[代码][代码]</[代码][代码]return_msg[代码][代码]><[代码][代码]result_code[代码][代码]>[代码][代码]<![CDATA[FAIL]]>[代码][代码]</[代码][代码]result_code[代码][代码]><[代码][代码]err_code[代码][代码]>[代码][代码]<![CDATA[PARAM_ERROR]]>[代码][代码]</[代码][代码]err_code[代码][代码]><[代码][代码]err_code_des[代码][代码]>[代码][代码]<![CDATA[参数错误:send_name字段必填,并且少于32字符]]>[代码][代码]</[代码][代码]err_code_des[代码][代码]><[代码][代码]mch_billno[代码][代码]>[代码][代码]<![CDATA[150820463120190425947306011]]>[代码][代码]</[代码][代码]mch_billno[代码][代码]><[代码][代码]mch_id[代码][代码]>[代码][代码]<![CDATA[XXXX82XX631]]>[代码][代码]</[代码][代码]mch_id[代码][代码]><[代码][代码]wxappid[代码][代码]>[代码][代码]<![CDATA[XXXXXXXXXXXXX]]>[代码][代码]</[代码][代码]wxappid[代码][代码]><[代码][代码]re_openid[代码][代码]>[代码][代码]<![CDATA[XXXXXXXXXXX]]>[代码][代码]</[代码][代码]re_openid[代码][代码]><[代码][代码]total_amount[代码][代码]>1</[代码][代码]total_amount[代码][代码]></[代码][代码]xml[代码][代码]>[代码] 同时验签是通过的 [图片] Java 代码块 [代码]/**[代码][代码] [代码][代码]* 需要证书的请求[代码][代码] [代码][代码]* @param strUrl String[代码][代码] [代码][代码]* @param reqData 向wxpay post的请求数据 Map[代码][代码] [代码][代码]* @param connectTimeoutMs 超时时间,单位是毫秒[代码][代码] [代码][代码]* @param readTimeoutMs 超时时间,单位是毫秒[代码][代码] [代码][代码]* @return API返回数据[代码][代码] [代码][代码]* @throws Exception[代码][代码] [代码][代码]*/[代码][代码]public[代码] [代码]String requestWithCert(String strUrl, Map<String, String> reqData,[代码][代码] [代码][代码]int[代码] [代码]connectTimeoutMs, [代码][代码]int[代码] [代码]readTimeoutMs) [代码][代码]throws[代码] [代码]Exception {[代码][代码] [代码][代码]String UTF8 = [代码][代码]"UTF-8"[代码][代码];[代码][代码] [代码][代码]String reqBody = WXPayUtil.mapToXml(reqData);[代码][代码] [代码][代码]System.out.println(reqBody);[代码][代码] [代码][代码]URL httpUrl = [代码][代码]new[代码] [代码]URL(strUrl);[代码][代码] [代码][代码]char[代码][代码][] password = config.getMchID().toCharArray();[代码][代码] [代码][代码]InputStream certStream = config.getCertStream();[代码][代码] [代码][代码]KeyStore ks = KeyStore.getInstance([代码][代码]"PKCS12"[代码][代码]);[代码][代码] [代码][代码]ks.load(certStream, password);[代码] [代码] [代码][代码]// 实例化密钥库 & 初始化密钥工厂[代码][代码] [代码][代码]KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());[代码][代码] [代码][代码]kmf.init(ks, password);[代码] [代码] [代码][代码]// 创建SSLContext[代码][代码] [代码][代码]SSLContext sslContext = SSLContext.getInstance([代码][代码]"TLS"[代码][代码]);[代码][代码] [代码][代码]sslContext.init(kmf.getKeyManagers(), [代码][代码]null[代码][代码], [代码][代码]new[代码] [代码]SecureRandom());[代码][代码] [代码][代码]HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());[代码] [代码] [代码][代码]HttpURLConnection httpURLConnection = (HttpURLConnection) httpUrl.openConnection();[代码] [代码] [代码][代码]httpURLConnection.setDoOutput([代码][代码]true[代码][代码]);[代码][代码] [代码][代码]httpURLConnection.setRequestMethod([代码][代码]"POST"[代码][代码]);[代码][代码] [代码][代码]httpURLConnection.setConnectTimeout(connectTimeoutMs);[代码][代码] [代码][代码]httpURLConnection.setReadTimeout(readTimeoutMs);[代码][代码] [代码][代码]httpURLConnection.connect();[代码][代码] [代码][代码]OutputStream outputStream = httpURLConnection.getOutputStream();[代码][代码] [代码][代码]outputStream.write(reqBody.getBytes(UTF8));[代码] [代码] [代码][代码]// if (httpURLConnection.getResponseCode()!= 200) {[代码][代码] [代码][代码]// throw new Exception(String.format("HTTP response code is %d, not 200", httpURLConnection.getResponseCode()));[代码][代码] [代码][代码]// }[代码] [代码] [代码][代码]//获取内容[代码][代码] [代码][代码]InputStream inputStream = httpURLConnection.getInputStream();[代码][代码] [代码][代码]BufferedReader bufferedReader = [代码][代码]new[代码] [代码]BufferedReader([代码][代码]new[代码] [代码]InputStreamReader(inputStream, UTF8));[代码][代码] [代码][代码]final[代码] [代码]StringBuffer stringBuffer = [代码][代码]new[代码] [代码]StringBuffer();[代码][代码] [代码][代码]String line = [代码][代码]null[代码][代码];[代码][代码] [代码][代码]while[代码] [代码]((line = bufferedReader.readLine()) != [代码][代码]null[代码][代码]) {[代码][代码] [代码][代码]stringBuffer.append(line);[代码][代码] [代码][代码]}[代码][代码] [代码][代码]String resp = stringBuffer.toString();[代码][代码] [代码][代码]if[代码] [代码](stringBuffer!=[代码][代码]null[代码][代码]) {[代码][代码] [代码][代码]try[代码] [代码]{[代码][代码] [代码][代码]bufferedReader.close();[代码][代码] [代码][代码]} [代码][代码]catch[代码] [代码](IOException e) {[代码][代码] [代码][代码]// e.printStackTrace();[代码][代码] [代码][代码]}[代码][代码] [代码][代码]}[代码][代码] [代码][代码]if[代码] [代码](inputStream!=[代码][代码]null[代码][代码]) {[代码][代码] [代码][代码]try[代码] [代码]{[代码][代码] [代码][代码]inputStream.close();[代码][代码] [代码][代码]} [代码][代码]catch[代码] [代码](IOException e) {[代码][代码] [代码][代码]// e.printStackTrace();[代码][代码] [代码][代码]}[代码][代码] [代码][代码]}[代码][代码] [代码][代码]if[代码] [代码](outputStream!=[代码][代码]null[代码][代码]) {[代码][代码] [代码][代码]try[代码] [代码]{[代码][代码] [代码][代码]outputStream.close();[代码][代码] [代码][代码]} [代码][代码]catch[代码] [代码](IOException e) {[代码][代码] [代码][代码]// e.printStackTrace();[代码][代码] [代码][代码]}[代码][代码] [代码][代码]}[代码][代码] [代码][代码]if[代码] [代码](certStream!=[代码][代码]null[代码][代码]) {[代码][代码] [代码][代码]try[代码] [代码]{[代码][代码] [代码][代码]certStream.close();[代码][代码] [代码][代码]} [代码][代码]catch[代码] [代码](IOException e) {[代码][代码] [代码][代码]// e.printStackTrace();[代码][代码] [代码][代码]}[代码][代码] [代码][代码]}[代码][代码] [代码][代码]// if (httpURLConnection!=null) {[代码][代码] [代码][代码]// httpURLConnection.disconnect();[代码][代码] [代码][代码]// }[代码] [代码] [代码][代码]return[代码] [代码]resp;[代码][代码]}[代码] 请求发红包的URL为:https://api.mch.weixin.qq.com/mmpaymkttransfers/sendminiprogramhb p12的证书已导入,商户API-Key也是正确的 参考的项目为: [代码]<[代码][代码]dependency[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]groupId[代码][代码]>com.objcoding</[代码][代码]groupId[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]artifactId[代码][代码]>WXPay-SDK-Java</[代码][代码]artifactId[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]version[代码][代码]>0.0.5</[代码][代码]version[代码][代码]>[代码][代码]</[代码][代码]dependency[代码][代码]>[代码]github网址:https://github.com/objcoding/WXPay-SDK-Java 参考编写的官方文档:https://pay.weixin.qq.com/wiki/doc/api/tools/miniprogram_hb.php?chapter=13_9&index=2 需要技术支持,谢谢。 同时 错误提示的“参数错误:send_name字段必填,并且少于32字符” 我已经给了参数send_name,根据官方的文档提示,无法定位到问题,需要官方处理