1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 微信开发之---查询公众号发送的红包

微信开发之---查询公众号发送的红包

时间:2021-06-20 03:19:18

相关推荐

微信开发之---查询公众号发送的红包

查询公众号发送的现金红包接口地址:

【微信支付】现金红包开发者文档

/*** 红包查询接口*/@Overridepublic JSONObject getwxhb(String openid,String orderid){JSONObject rejsonObject=new JSONObject();String mch_id=wechatPayConfig.getMch_id();String certificatePath=wechatPayConfig.getCertificatePath();//随机字符串和红包金额,金额单位为分String nonce_str= StringUtils.getNonce_str();String sign=this.getWxsearchSign(nonce_str,orderid);//封装请求参数StringBuilder reqXmlStr = new StringBuilder();reqXmlStr.append("<xml>");reqXmlStr.append("<sign><![CDATA["+sign+"]]></sign>");reqXmlStr.append("<mch_billno><![CDATA["+ orderid +"]]></mch_billno>");reqXmlStr.append("<mch_id><![CDATA["+wechatPayConfig.getMch_id()+"]]></mch_id>");reqXmlStr.append("<appid><![CDATA["+wechatPayConfig.getWxappid()+"]]></appid>");reqXmlStr.append("<bill_type><![CDATA[MCHT]]></bill_type>");reqXmlStr.append("<nonce_str><![CDATA["+nonce_str+"]]></nonce_str>");reqXmlStr.append("</xml>");String reqXmlStrn=reqXmlStr.toString();log.info("微信红包查询接口:"+reqXmlStrn);String transUrl = "https://api.mch./mmpaymkttransfers/gethbinfo";HttpPost httpPost = new HttpPost(transUrl);try {// 得指明使用UTF-8编码,否则到API服务器XML的中文不能被成功识别StringEntity postEntity = new StringEntity(reqXmlStrn, "UTF-8");httpPost.addHeader("Content-Type", "text/xml");httpPost.setEntity(postEntity);//根初始化requestConfig 连接超时时间,默认10秒 传输超时时间,默认30秒RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(10000).setConnectTimeout(30000).build();httpPost.setConfig(requestConfig);CloseableHttpClient httpClient=WxUtils.loadCertificate(mch_id,certificatePath);HttpResponse response = httpClient.execute(httpPost);try {HttpEntity entity = response.getEntity();String result = EntityUtils.toString(entity, "UTF-8");log.info(result);//解析是否发送成功,成功则返回成功标志,String jsonst= XmlUtils.xmlToJson(result);JSONObject jsonObject=JSONObject.parseObject(jsonst);rejsonObject=jsonObject.getJSONObject("xml");} catch (Exception e) {e.printStackTrace();}} catch (Exception e) {e.printStackTrace();} finally {httpPost.abort();}return rejsonObject;}/*** 查询红包发送结果签名算法* @param nonce_str* @param orderid* @return*/private String getWxsearchSign(String nonce_str,String orderid) {Map<String, Object> paramMap = new HashMap<String, Object>();//随机字符串paramMap.put("nonce_str", nonce_str);//商户订单号paramMap.put("mch_billno", String.valueOf(orderid));//商户号paramMap.put("mch_id",wechatPayConfig.getMch_id() );//公众账号appidparamMap.put("appid", wechatPayConfig.getWxappid());//备注paramMap.put("bill_type", "MCHT");String sign= WxUtils.getSign(paramMap,wechatPayConfig.getMchkey());return sign;}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。