微信红包支付--发放普通红包
String currTime = TenpayUtil.getCurrTime();//8位日期String strTime = currTime.substring(8, currTime.length());//四位随机数String strRandom = TenpayUtil.buildRandom(4) + "";String str=currTime.substring(0, currTime.length()-6);//10位序列号,可以自行调整。String strReq = strTime + strRandom;String nonce_str=strReq;//随机字符串String mch_id="10016225";//商户号String mch_billno=mch_id+str+strReq;//商户订单号String wxappid="wx1ccccccccccc6f";//公众账号appidString send_name="shanghuming";//商户名称(微信红包发送者名称,最好用英文)String re_openid="oYxxxxxxdcdcddddddddc";//用户openIdint total_amount=100;//付款金额int total_num=1;//红包发放总人数String wishing="happy";//红包祝福语String client_ip="192.168.1.00";//ip地址String act_name="ceshiactivity";//活动名称String remark="ceshi";String scene_id="PRODUCT_5";//场景idString key="aaaaaaaaaaaaaaa";//商户号API密钥SortedMap<String, String> packageParams = new TreeMap<String, String>();packageParams.put("act_name", act_name);packageParams.put("client_ip", client_ip);packageParams.put("mch_billno", mch_billno);packageParams.put("mch_id", mch_id);packageParams.put("nonce_str",nonce_str);packageParams.put("remark", remark);packageParams.put("re_openid", re_openid);packageParams.put("send_name", send_name);packageParams.put("scene_id", scene_id);packageParams.put("total_amount", String.valueOf(total_amount));packageParams.put("total_num", String.valueOf(total_num));packageParams.put("wishing", wishing);packageParams.put("wxappid", wxappid);//生成签名String sign = createSign(packageParams,key,"UTF-8");String xmlTest="<xml>"+ "<act_name>"+act_name+"</act_name>"+ "<client_ip>"+client_ip+"</client_ip>"+ "<mch_billno>"+mch_billno+"</mch_billno>"+ "<mch_id>"+mch_id+"</mch_id>"+ "<nonce_str>"+nonce_str+"</nonce_str>"+ "<remark>"+remark+"</remark>"+ "<re_openid>"+re_openid+"</re_openid>"+ "<send_name>"+send_name+"</send_name>"+ "<scene_id>"+scene_id+"</scene_id>"+ "<total_amount>"+total_amount+"</total_amount>"+ "<total_num>"+total_num+"</total_num>"+ "<wxappid>"+wxappid+"</wxappid>"+ "<wishing>"+wishing+"</wishing>"+ "<sign>"+sign+"</sign>"+"</xml>";System.out.println(xmlTest);String notify_url="https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack";String prepay_id="";try {prepay_id =reqPost(notify_url, xmlTest);if(prepay_id.contains("成功")){request.setAttribute("SUCCESSMsg", "微信红包支付接口成功");response.sendRedirect("success.jsp");}else{request.setAttribute("ErrorMsg", "微信红包支付接口出错");response.sendRedirect("error.jsp");}} catch (Exception e1) {// TODO Auto-generated catch blocke1.printStackTrace();}
public String createSign(SortedMap<String, String> paraMap,String key,String charset) {StringBuffer sb = new StringBuffer();Set es = paraMap.entrySet();Iterator it = es.iterator();while (it.hasNext()) {Map.Entry entry = (Map.Entry) it.next();String k = (String) entry.getKey();String v = (String) entry.getValue();if (null != v && !"".equals(v) && !"sign".equals(k)&& !"key".equals(k)) {sb.append(k + "=" + v + "&");}}sb.append("key=" + key);System.out.println("===========签名参数====="+sb.toString());String sign = MD5Util.MD5Encode(sb.toString(), "UTF-8").toUpperCase();System.out.println("===========生成的签名是====="+sign);return sign;}
请求微信红包接口:
public String reqPost(String url,String xmlParam) throws Exception{KeyStore keyStore = KeyStore.getInstance("PKCS12");//读取商户证书(我下载下来的证书保存到D盘,根据自己实际情况填写)FileInputStream instream = new FileInputStream(new File("D:/10016225.p12"));try {keyStore.load(instream, "10016225".toCharArray());} finally {instream.close();}// Trust own CA and all self-signed certsSSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, "10016225".toCharArray()).build();// Allow TLSv1 protocol onlySSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext,new String[] { "TLSv1" },null,SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build();HttpPost httpPost = new HttpPost(url);CloseableHttpResponse response1;String prepay_id = "";try {httpPost.setEntity(new StringEntity(xmlParam));response1 = httpclient.execute(httpPost);try {int status = response1.getStatusLine().getStatusCode();if(status>=200&&status<400){System.out.println(response1.getStatusLine());HttpEntity entity1 = response1.getEntity();String jsonStr = EntityUtils.toString(entity1, "UTF-8");Map<String, Object> dataMap = new HashMap<String, Object>();System.out.println("返回数据:"+jsonStr);if(jsonStr.indexOf("FAIL")!=-1){return prepay_id;}//我的项目的编码为GBK,再次改编码防止乱码出错jsonStr=new String(jsonStr.getBytes("UTF-8"), "GBK");Map map = doXMLParse(jsonStr);String return_code = (String) map.get("return_code");if("SUCCESS".equals(return_code)){prepay_id = (String) map.get("return_msg");}}return prepay_id;} catch (Exception e) {e.printStackTrace();} finally {response1.close();}} catch (ClientProtocolException e1) {e1.printStackTrace();} catch (IOException e1) {// TODO Auto-generated catch blocke1.printStackTrace();}return null;}/*** 解析xml,返回第一级元素键值对。如果第一级元素有子节点,则此节点的值是子节点的xml数据。* @param strxml* @return* @throws JDOMException* @throws IOException*/public static Map doXMLParse(String strxml) throws Exception {if(null == strxml || "".equals(strxml)) {return null;}Map m = new HashMap();InputStream in = new ByteArrayInputStream(strxml.getBytes());SAXBuilder builder = new SAXBuilder();Document doc = builder.build(in);Element root = doc.getRootElement();List list = root.getChildren();Iterator it = list.iterator();while(it.hasNext()) {Element e = (Element) it.next();String k = e.getName();String v = "";List children = e.getChildren();if(children.isEmpty()) {v = e.getTextNormalize();} else {v = getChildrenText(children);}m.put(k, v);}//关闭流in.close();return m;}
微信红包支付--发放普通红包相关推荐
- 某销售公司在年末的时候会向员工发放红包,发放的红包金额共有5种,获取的条件各不相同: 1) 五颗星红包,每人8000元,平均月绩效大于80件商品(>80),并且在本年度满勤; 2) 四颗星红包,每
某销售公司在年末的时候会向员工发放红包,发放的红包金额共有5种,获取的条件各不相同: 五颗星红包,每人8000元,平均月绩效大于80件商品(>80),并且在本年度满勤: 四颗星红包,每人4000 ...
- 企业微信发送企业红包java_发放企业红包
API接口协议 发放规则: 发送频率限制---默认1800/min 发送个数上限---默认1800/min 场景金额限制---默认红包金额为1-200元,如有需要,可前往商户平台进行设置和申请 其他限 ...
- 发放普通红包 php,发放普通红包
# 调用方法 要在实现发红包功能,只需要按以下例子调用即可.开发者只需要保证 [红包前置配置](红包前置配置.md) 正确,参数正确就可以. ~~~ $appid = '你的公众号appid'; $o ...
- php微信商务平台 红包调用,微信平台红包接口怎么调用?微信支付商户平台红包发放接口调用图文教程[多图]...
微信平台红包接口怎么调用?估计很多商家都还不太会操作吧?别着急,下面是友情小编搜集相关资料整理出来的微信支付商户平台红包发放接口调用图文教程,希望可以帮到大家,现在就跟随小编一起看看吧!!! 首先,商 ...
- python 微信支付 小程序红包 发放红包接口
python 微信支付 小程序红包 发放红包接口 文章目录 python 微信支付 小程序红包 发放红包接口 前言 一.官方文档 二.使用步骤 1.引入,直接复制粘贴以下代码,新建wx_pay.py ...
- 微信支付推出限量红包封面 两大途径赢取
距离农历新年还有不足10天,年味越来越浓.微信支付特别定制虎年生肖红包封面,由新朋友"虎豆妞"为用户送上真挚祝福.这款红包封面将从1月22日起限量发放,用户通过"微信支付 ...
- 微信服务号+支付+php,微信服务号发送营销红包给关注用户步骤及部分php代码
微信红包 一.前言: 这里主要讲述的是微信服务号给关注用户发送微信红包的相关内容:主要使用的业务场景有:1.业务员匆匆销员的奖励:2.现场会议互动抽奖:3.微信推广转发奖励:4.其他等等等,大开脑洞想 ...
- 微信开发-发放普通红包(java代码实例)
一.介绍 前一阵子做了个微信发放普通红包的功能,在这记录下开发思路 二.微信官网 https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.ph ...
- 微信红包雨怎么抢_1月26日晚8点微信红包雨发放时间表 怎么抢红包全攻略
1月26日晚8点微信红包雨发放时间表 怎么抢红包全攻略 据1月26日消息,微信官方将在今晚8点开启一轮红包雨[在哪里抢],用户通过手机摇一摇的方式可抢红包. 延伸阅读: 抢红包攻略: 1月26日晚8点 ...
最新文章
- 基于ipfire的open***功能--client to net (Roadwarrior)配置(一)
- 人工智能实践:TensorFlow笔记学习(二)—— Python语法串讲
- 【fjwc2015】世界树
- wxWidgets:wxMDIChildFrame类用法
- 常用数据结构及复杂度
- 使用git管理github项目
- Visual Studio 2010 调试 C 语言程序
- Vue前后端对接时判断是否与后端连接成功
- 酒泉于洋计算机学校,于洋
- 【Oracle】并行等待之PX Deq Credit: need buffer
- 8255A置位复位控制字
- Provisioning Services 7.8 入门系列教程之九 手动更新虚拟磁盘
- 2021下半年软考网络工程师上午真题(二)
- 通过电脑从Ovi商店下载软件并安装
- Windows Terminal美化增强指南
- Java 方法的重载与重写
- html 倒计时毫秒,实现毫秒级倒计时
- 结构化数据,半结构化数据,非结构化数据(区别)
- 【C++】三大易混概念之覆盖
- python列表两两相减_Python数据分析实例一:医院药品销售数据
热门文章
- ubuntu1804
- eeprom的wp 引脚_24C04WP 数据手册 PDF - EEPROM - ST - DataSheet5.cn
- 一个请求结束之后再发送另外一个请求,需要连着发很多请求的方法-promise
- 物联网设备安全2.1 酒店门锁和磁卡
- badger和rocksDB性能对比
- 计算机函数sumif求平均值,『如何用sumif求平均年龄』excel表中如何算平均数及标准差...
- 动网7.1 SP1得到后台密码得到WebShell
- 珍惜那些在背后默默为你付出的人
- InstructPix2Pix: 随口修图
- 管理费用负数报不了怎么办_管理费用发生额是负数怎么办