激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Java教程 - java微信公眾號企業付款開發

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

2021-06-02 14:06shaomiaojava Java教程

這篇文章主要為大家詳細介紹了java微信公眾號企業付款開發,具有一定的參考價值,感興趣的小伙伴們可以參考一下

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

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

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

java代碼 定義所傳遞的參數

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
@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 靜態方法

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**
  * 獲取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/oauth2/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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/**
 * 企業付款
 *
 * @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<string, string> params_map = new linkedhashmap<string, string>();
  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<element> 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;
}

微信簽名驗證證書

驗證證書公共方法

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
 * 驗證證書公共方法
 *
 * @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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/**
  * 微信支付拼接xml
  *
  * @param params
  * @return
  */
 public static string toxml(map<string, string> params)
 {
  string xml = "<xml>";
  for (string key : params.keyset())
  {
   if ("body".equals(key) || "attach".equals(key)
     || "sign".equals(key))
   {
    xml += "<" + key + "><![cdata[" + params.get(key) + "]]></"
      + key + ">";
   }
   else
   {
    xml += "<" + key + ">" + params.get(key) + "</" + key + ">";
   }
  }
  xml += "</xml>";
  return xml;
 }

微信公共方法  字符串md5

加密
用來加密簽名

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/***
  * 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();
 }

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。

原文鏈接:https://blog.csdn.net/shaomiaojava/article/details/50562550

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 国产视频软件在线 | 国产精品久久久不卡 | 国产精品视频一区二区三区四区国 | 久久国产精品无码网站 | 免费在线观看毛片 | 性爱在线免费视频 | 成人精品一区二区 | 日韩毛片一区二区三区 | 欧美成人精品欧美一级乱黄 | 福利免费观看 | 精品久久久一二三区播放播放播放视频 | 国产一级毛片av | 国产精品久久久久久久久久久久午夜 | 蜜桃欧美性大片免费视频 | 有色视频在线观看 | 中国大陆高清aⅴ毛片 | 91羞羞| 九草在线| 他也色在线视频 | 成人午夜精品久久久久久久蜜臀 | 国产精品免费一区二区 | 色七七久久影院 | 欧美一区在线观看视频 | 亚洲婷婷日日综合婷婷噜噜噜 | 日本高清一级片 | 国产在线免 | 欧美国产一区二区三区激情无套 | 激情午夜天 | 黄色一级片在线免费观看 | 欧美一级精品 | 国产1区在线 | 精精国产xxxx视频在线野外 | 最新久久免费视频 | 国产精品久久久免费观看 | 久久精品一二三区 | 国产99视频在线观看 | 九九热精品免费视频 | 成年人网站国产 | 成人爱爱电影 | 福利一区二区三区视频在线观看 | 亚洲视频在线一区二区 |