老熟女激烈的高潮_日韩一级黄色录像_亚洲1区2区3区视频_精品少妇一区二区三区在线播放_国产欧美日产久久_午夜福利精品导航凹凸

重慶分公司,新征程啟航

為企業提供網站建設、域名注冊、服務器等服務

java微信公眾號企業付款開發

本文為大家分享了java微信公眾號企業付款的開發代碼,供大家參考,具體內容如下

網站建設公司,為您提供網站建設,網站制作,網頁設計及定制網站建設服務,專注于成都定制網站,高端網頁制作,對成都社區文化墻等多個行業擁有豐富的網站建設經驗的網站建設公司。專業網站設計,網站優化推廣哪家好,專業營銷推廣優化,H5建站,響應式網站。

詳情參照微信開發者文檔 企業付款文檔

java微信公眾號企業付款開發 

java代碼 定義所傳遞的參數

 @RequestMapping(value = "zhifu", method = RequestMethod.GET)
 public @ResponseBody String getWeixinOpenid(String code,
   HttpServletRequest request)
 {
  // 訂單號 自定義 生成32位uuid
  String partner_trade_no = UUIDGenerator.getUUID();
  // 隨機數
  String nonce_str = UUIDGenerator.getUUID();
  // 轉賬金額(分為單位)1-200
  int jine = 100;
  // 企業付款信息
  String desc = "轉賬";
  // ip地址
  String spbill_create_ip = "xx.xx.xx";
  // re_user_name
  String re_user_name = "xx";

  String check_name = CheckName.NO_CHECK.toString();
  String zfpath = "D:/apiclient_cert.p12";
  try
  {
   // 獲取openid
   String openid = WeChatUtil.getByOpenid(appid, secret, code);
   // 付款
   boolean flag = WeChatUtil.enterprisePayment(openid, appid, mchid,
     nonce_str, partner_trade_no, re_user_name, jine, desc,
     spbill_create_ip, check_name, key, zfpath);
   // 成功
   if (flag)
   {
    return "SUCCESS";
   }

  }
  catch (Exception e)
  {
   System.err.println(e.getStackTrace());
  }
  return "FAIL";
 }

獲取關注本公眾號用戶唯一標示  獲取openid

java代碼 獲取openid 靜態方法

/**
  * 獲取openid
  * 
  * @description
  * @param appid
  * @param secret
  * @param code
  * @return
  * @author shaomiao
  */
 public static String getByOpenid(String appid, String secret, String code)
 {
  String url = "https://api.weixin.qq.com/sns/oauth3/access_token?appid="
    + appid + "&secret=" + secret + "&code=" + code
    + "&grant_type=authorization_code";
  String jsonstring = WeChatUtil.getJsonString(url);
  JSONObject json1 = JSONObject.parseObject(jsonstring);
  String openid = json1.get("openid").toString();
  return openid;

 }

企業付款的調用公共方法

java代碼
post提交 xml參數
解析回調的xml

 /**
  * 企業付款
  * 
  * @description
  * @param openid
  * @param appid
  * @param mchid 商戶id
  * @param nonce_str
  * @param partner_trade_no
  * @param re_user_name
  * @param jine
  * @param desc
  * @param spbill_create_ip
  * @param check_name
  * @return
  * @author Jobs
  * @throws IOException
  * @throws ClientProtocolException
  */
 public static boolean enterprisePayment(String openid, String appid,
   String mchid, String nonce_str, String partner_trade_no,
   String re_user_name, int jine, String desc, String spbill_create_ip,
   String check_name, String key, String zfpath) throws Exception
 {
  boolean getSuccess = true;
  if (null != openid)
  {
   // zf
   Map params_map = new LinkedHashMap();
   StringBuffer param = new StringBuffer();
   // appid
   param.append("mch_appid=" + appid);
   // 商戶id
   param.append("&mchid=" + mchid);
   // 隨機字符串
   // param.append("&nonce_str="
   // + ZifwUtil.string2MD5(new Date().getTime() + ""));
   param.append("&nonce_str=" + nonce_str);
   // 訂單號自定義
   param.append("&partner_trade_no=" + partner_trade_no);

   param.append("&openid=" + openid);
   // 校驗用戶姓名選項
   /**
    * NO_CHECK:不校驗真實姓名
    * FORCE_CHECK:強校驗真實姓名(未實名認證的用戶會校驗失敗,無法轉賬)
    * OPTION_CHECK:針對已實名認證的用戶才校驗真實姓名(未實名認證用戶不校驗,可以轉賬成功)
    */
   param.append("&check_name=" + check_name);
   // 收款用戶姓名
   param.append("&re_user_name=" + re_user_name);
   // 金額
   param.append("&amount=" + jine);
   // 企業付款描述信息
   param.append("&desc=" + desc);
   // Ip地址
   param.append("&spbill_create_ip=" + spbill_create_ip);

   String[] params = param.toString().split("&");
   Arrays.sort(params);
   param = new StringBuffer();
   for (String p : params)
   {
    String[] value = p.split("=");
    params_map.put(value[0], value[1]);
    param.append(value[0] + "=" + value[1] + "&");
   }

   // 簽名最后
   String sign = ZifwUtil.string2MD5(param.toString() + "key=" + key)
     .toUpperCase();
   params_map.put("sign", sign);
   String reqStr = ZifwUtil.toXml(params_map);
   // ZHENGSHU
   CloseableHttpClient httpclient = certificateValidation(zfpath,
     mchid);

   HttpPost httppost = new HttpPost(
     "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers");
   StringEntity myEntity = new StringEntity(reqStr, "UTF-8");
   httppost.setEntity(myEntity);
   System.out.println("executing request" + httppost.getRequestLine());

   CloseableHttpResponse response = httpclient.execute(httppost);
   System.out.println(response.getStatusLine());

   HttpEntity resEntity = response.getEntity();
   InputStreamReader reader = new InputStreamReader(
     resEntity.getContent(), "UTF-8");
   char[] buff = new char[1024];
   int length = 0;
   StringBuffer strhuxml = new StringBuffer();
   while ((length = reader.read(buff)) != -1)
   {
    strhuxml.append(new String(buff, 0, length));
    System.out.println(new String(buff, 0, length));
   }
   // httpclient.close();
   httpclient.getConnectionManager().shutdown();

   // String ret = ZifwUtil.post(
   // "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers",
   // reqStr);

   // 解析傳過來的xml
   Document document = DocumentHelper.parseText(strhuxml.toString());
   // 得到xml根元素
   Element root = document.getRootElement();
   // 得到根元素的所有子節點
   List elementList = root.elements();
   String errors = "";
   for (Element e : elementList)
   {

    // result_code業務
    if ("return_code".equals(e.getName())
      && !"SUCCESS".equals(e.getText()))
    {
     getSuccess = false;
    }
    if ("result_code".equals(e.getName())
      && !"SUCCESS".equals(e.getText()))
    {
     getSuccess = false;
    }
   }

  }
  return getSuccess;
 }

微信簽名驗證證書

驗證證書公共方法

 /**
  * 驗證證書公共方法
  * 
  * @description
  * @param zfpath 證書的路徑
  * @param mchid 商戶id
  * @return
  * @throws Exception
  * @author Jobs
  */
 // shanghuid
 // 驗證證書
 @SuppressWarnings("deprecation")
 public static CloseableHttpClient certificateValidation(String zfpath,
   String mchid) throws Exception
 {
  // 指定讀取證書格式為PKCS12
  KeyStore keyStore = KeyStore.getInstance("PKCS12");
  // 證書地址
  FileInputStream instream = new FileInputStream(new File(zfpath));
  try
  {
   keyStore.load(instream, mchid.toCharArray());
  }
  finally
  {
   instream.close();
  }

  // Trust own CA and all self-signed certs
  SSLContext sslcontext = SSLContexts.custom()
    .loadKeyMaterial(keyStore, mchid.toCharArray()).build();
  // Allow TLSv1 protocol only
  SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
    sslcontext, new String[] { "TLSv1" }, null,
    SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
  CloseableHttpClient httpclient = HttpClients.custom()
    .setSSLSocketFactory(sslsf).build();
  return httpclient;
 }

微信公共方法  字符串轉xml

/**
  * 微信支付拼接xml
  * 
  * @param params
  * @return
  */
 public static String toXml(Map params)
 {
  String xml = "";
  for (String key : params.keySet())
  {
   if ("body".equals(key) || "attach".equals(key)
     || "sign".equals(key))
   {
    xml += "<" + key + ">";
   }
   else
   {
    xml += "<" + key + ">" + params.get(key) + "";
   }
  }
  xml += "";
  return xml;
 }

微信公共方法  字符串MD5

加密
用來加密簽名

/***
  * MD5加碼 生成32位md5碼
  */
 public static String string2MD5(String inStr)
 {
  StringBuffer buf = new StringBuffer();
  try
  {
   MessageDigest md = MessageDigest.getInstance("MD5");
   md.update(inStr.getBytes("utf-8"));
   byte b[] = md.digest();

   int i;

   for (int offset = 0; offset < b.length; offset++)
   {
    i = b[offset];
    if (i < 0)
     i += 256;
    if (i < 16)
     buf.append("0");
    buf.append(Integer.toHexString(i));
   }
  }
  catch (Exception e)
  {
   e.printStackTrace();
  }
  return buf.toString();
 }

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持創新互聯。


網頁名稱:java微信公眾號企業付款開發
網站網址:http://www.xueling.net.cn/article/ippjod.html

其他資訊

在線咨詢
服務熱線
服務熱線:028-86922220
TOP
主站蜘蛛池模板: 欧洲视频在线观看 | 波多野结衣AV全免费观 | 精品人妻一区二区三区综合部 | 九草在线观看 | 国产视频精品一区二区三区 | 小嫩妇好紧好爽再快视频 | 把腿张开老子cao烂你 | av大全在线观看 | 成人爽a毛片免费啪啪红桃视频 | 欧美黑人又粗又大又爽免费 | 久久久久久视频 | 亚洲精品国产精品国自产观看 | 新版天堂资源中文www连接 | 在线观看免费视频黄 | 免费观看激色视频网站在线观看 | JIZZJIZZ国产 | 国产精品人妻一区夜夜爱 | 亚洲AV最新高清每天更新 | 精品国产一区二区三区四区动漫a | 哪里可以看毛片 | 69爱爱视频 | 久久精品久久久久久久久久久久久 | 99久久精品国产国产毛片 | 亚洲国产欧美国产综合一区 | 欧美日韩一级有码在线视频 | 顶级欧美色妇XXXXX | 操穴影院 | 国产乱人视频在线播放 | 成人一区在线视频 | 91在线视频| 女人被做到高潮视频 | 久久婷婷国产91天堂综合精品 | 国产视频在线免费观看 | JAPANESE日本爆乳巨大 | 国内精品伊人久久久久影院麻豆 | 91成品视频 | 成人午夜爽爽爽免费视频 | 亚洲国产中文字幕在线 | 日本夜爽爽一二区 | 久久精品中文闷骚内射 | www.7788久久久久久久久 |