Micro-channel pay-mediated access to developer documentation

** Well, extra words to explain, however, here we take a look ye are micro-channel access SDK documentation
if man anxious, then transferred to please: https://www.jianshu.com/p/1015841aae48 (Download Demo fill the correct information directly from the transfer payments)
updated second Edition Demo: https://www.jianshu.com/p/1015841aae48
layout 2: http://www.jianshu.com/p/c417ce674eb3
possible intervention is not very good, heavy in learning, learning Kazakhstan, to follow my train of thought, must have patience, a lot of micro-channel pit, look under the parameters (important)
to obtain an IP address: http://pv.sohu.com/cityjson?ie=utf -8
test micro-channel data interface: https://pay.weixin.qq.com/wiki/tools/signverify/
micro-channel parameters
Demo: link: https://pan.baidu.com/s/1eS1tyWM password: 3xih
WRNING !! !
in class: WX_DATA_XINHAO_HAN set up micro-channel information
in the class AliPay_XINHAO_HAN_DATA set Alipay information
appid: your APPID
mch_id: merchant No.
nonce_str: generate a random string
body: product details
out_trade_no: Time
total_fee: Amount
spbill_create_ip: IP address
notify_url: callback address of the call after the success of
trade_type: the type of support (hardcoded "APP")
Step 1: you go to register some information about micro-channel official website and then get three of the following things
1. APPID 2. 3. your business number keys
on these things
information
basic information nonce_str: generate random string
random string generation:
they are generally fixed, and he is too lazy to write so find one, if you want to write your own then give you some ideas
first put AZ 0-9 writes a String array, and then take the index for by Random 32 times to
have a look at it online
MD5
MD5 method
copy the code
layout really uncomfortable, this stuff is not even a reference to the code no ???
the use of this method is such that
MD5 to use
the code to copy

//生成随机字符串
public staticStringgenNonceStr() {
Random random =newRandom();
returnMD5.getMessageDigest(String.valueOf(random.nextInt(10000)).getBytes());
}

public final staticStringgetMessageDigest(byte[] buffer) {
charhexDigits[] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
try{
MessageDigest mdTemp = MessageDigest.getInstance("MD5");
mdTemp.update(buffer);
byte[] md = mdTemp.digest();
intj = md.length;
charstr[] =new char[j *2];
intk =0;
for(inti =0;i < j;i++) {
bytebyte0 = md[i];
str[k++] = hexDigits[byte0 >>>4&0xf];
str[k++] = hexDigits[byte0 &0xf];
}
return newString(str);
}catch(Exception e) {
return null;
}
}

Basic information out_trade_no: time
this should be able to, is to use JAVA get your own current time format
such as: July 17, 2017 will be written 2,017,717
basic information spbill_create_ip: IP addresses
using network access: http://pv.sohu .com / cityjson ie = utf-8
? will give you a return var returnCitySN = { "cip": "219.144.202.177", "cid": "610100", "cname": " Xi'an, Shaanxi Province"};
yourself interception on OK
basic information notify_url: address to call when the callback success
backstage temporarily not provide an interface, then you just write
basic information mch_id: merchant number
for your business number
basic information body: product details
free to write
basic information total_fee: the amount of
random write
good the basic functions are introduced over the data
introduced micro-channel Sdk
the Android Studio applicable

compile'com.tencent.mm.opensdk: wechat-sdk-android- with-mta: + '
to just a few parameters to generate about sign
signature generation
here, you may ask what the hell is OrederSendInfo info ???
Remember : WX_DATA_XINHAO_HAN.API_KEY is your own keys
do not worry the old rules to copy the code

//生成预支付随机签名
public staticStringgenSign(OrederSendInfo info) {
StringBuffer sb =newStringBuffer(info.toString());
if(WX_DATA_XINHAO_HAN.API_KEY.equals("")) {
Toast.makeText(UIUtils.getContext(),"APP_ID为空",Toast.LENGTH_LONG).show();
}
//拼接密钥
sb.append("key=");
sb.append(WX_DATA_XINHAO_HAN.API_KEY);
String appSign = MD5.getMessageDigest(sb.toString().getBytes());
Log.e("Sign-------------","genSign: "+ appSign.toUpperCase());
returnappSign.toUpperCase();
}

Well now I explain to you what the hell is this OrederSendInfo info method parameter
that is actually a Bean
look at the code

public classOrederSendInfo {
privateStringappid;
privateStringmch_id;
privateStringnonce_str;
privateStringbody;
privateStringout_trade_no;
privateStringtotal_fee;
privateStringspbill_create_ip;
privateStringnotify_url;
privateStringtrade_type;
privateStringsign;
publicOrederSendInfo(String appid,String mch_id,String nonce_str,String body,String out_trade_no,String total_fee,String spbill_create_ip,String notify_url,String trade_type) {
this.appid= appid;
this.mch_id= mch_id;
this.nonce_str= nonce_str;
this.body= body;
this.out_trade_no= out_trade_no;
this.total_fee= total_fee;
this.spbill_create_ip= spbill_create_ip;
this.notify_url= notify_url;
this.trade_type= trade_type;
}
publicStringgetAppid() {
returnappid;
}
public voidsetAppid(String appid) {
this.appid= appid;
}
publicStringgetMch_id() {
returnmch_id;
}
public voidsetMch_id(String mch_id) {
this.mch_id= mch_id;
}
publicStringgetNonce_str() {
returnnonce_str;
}
public voidsetNonce_str(String nonce_str) {
this.nonce_str= nonce_str;
}
publicStringgetBody() {
returnbody;
}
public voidsetBody(String body) {
this.body= body;
}
publicStringgetOut_trade_no() {
returnout_trade_no;
}
public voidsetOut_trade_no(String out_trade_no) {
this.out_trade_no= out_trade_no;
}
publicStringgetTotal_fee() {
returntotal_fee;
}
public voidsetTotal_fee(String total_fee) {
this.total_fee= total_fee;
}
publicStringgetSpbill_create_ip() {
returnspbill_create_ip;
}
public voidsetSpbill_create_ip(String spbill_create_ip) {
this.spbill_create_ip= spbill_create_ip;
}
publicStringgetNotify_url() {
returnnotify_url;
}
public voidsetNotify_url(String notify_url) {
this.notify_url= notify_url;
}
publicStringgetTrade_type() {
returntrade_type;
}
public voidsetTrade_type(String trade_type) {
this.trade_type= trade_type;
}
publicStringgetSign() {
returnsign;
}
public voidsetSign(String sign) {
this.sign= sign;
}
//注意排序规则ASCII排序(一般按照A-Z,a-z)就行
@Override
publicStringtoString() {
return"appid="+appid+'&'+
"body="+body+'&'+
"mch_id="+mch_id+'&'+
"nonce_str="+nonce_str+'&'+
"notify_url="+notify_url+'&'+
"out_trade_no="+out_trade_no+'&'+
"spbill_create_ip="+spbill_create_ip+'&'+
"total_fee="+total_fee+'&'+
"trade_type="+trade_type+'&';
}
}

// remember to assign this Bean inside when you call, do not understand, then passed to the method signature sign of success is generated
signature generation completed
start uploading data to obtain a pre-payment interface
side here you may find there is a XStream less than
add this inside the Studio

compile ('com.thoughtworks.xstream:xstream:1.4.7') {
excludegroup:'xmlpull',module:'xmlpull'
}

Recompile
the code to copy

public static voidUnfiedOrder(OrederSendInfo orederSendInfo, finalListerner listerner) {
//生成sign签名
String sign = WXpayUtils.genSign(orederSendInfo);
//生成所需参数,为xml格式
orederSendInfo.setSign(sign.toUpperCase());
XStream xstream =newXStream();
xstream.alias("xml",OrederSendInfo.class);
finalString xml = xstream.toXML(orederSendInfo).replaceAll("__","_");
Log.e("xml---------------","UnfiedOrder: "+ xml);
//调起接口,获取预支付ID
OkHttpUtils.ResultCallback resultCallback =newOkHttpUtils.ResultCallback() {
@Override
public voidonSuccess(String response) {
Log.e("返回的数据","onSuccess: "+ response);
String data = response;
data = data.replaceAll("","");
listerner.Success(data);
}
@Override
public voidonFailure(Exception e) {
listerner.Faiulre(e.toString());
}
};
try{
OkHttpUtils.post(WX_DATA_XINHAO_HAN.UNIFIED_ORDER,resultCallback, newString(xml.getBytes("UTF-8"),"ISO8859-1"));
}catch(UnsupportedEncodingException e) {
e.printStackTrace();
}
}

As Listnener inside
where
the interface
code duplication

public interfaceListerner {
voidSuccess(String data);
voidFaiulre(String data);
}

After the end of the micro-channel to get data directly from the micro-channel pay off
tune from the micro-channel pay
starts filling data
to fill data
Special thanks: Grave Digger
blog address: http://www.jianshu.com/p/9a3127cfda4d
I integrated by his given DEMO and a set of simple Demo
Download: link: https://pan.baidu.com/s/1c2zURjq password: jpr5
use: you may several parts of this attention being given attention !!!
WXActivity
because micro letter it hung, you have to call WXEntryActivity to follow, create an Activity name people directly in my tool kit that
you're in Activity-> WXEntryActivity this method to create your own
direct copy this code

WxMain.setStringOnListener(WXEntryActivity.this);
//如果是支付
WxMain.WXMessage wxMessage;
if(baseResp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
intcode = baseResp.errCode;
switch(code) {
case0:
if(wxMessage!=null)
wxMessage.message("支付成功",0,"0.0");
//支付成功
break;
case-1:
if(wxMessage!=null)
wxMessage.message("支付失败",-1,"0.0");
//支付失败
finish();
break;
case-2:
if(wxMessage!=null)
wxMessage.message("支付取消",-2,"0.0");
//支付取消
finish();
break;
default:
if(wxMessage!=null)
wxMessage.message("支付失败",-3,"0.0");
//支付失败
setResult(RESULT_OK);
finish();
break;
}
return;
}

Use is this:
Use
the first to describe your product, the second is money, the callback is successful only 0
0 successful
-1 failed to pay
-2 payment canceled
-3 payment fails
, then use the copy it directly into
a word micro-contrast letter Alipay trouble than even the bold style
that white is the encrypted data is sent to give you resolve what data is then transferred from the pay, roughly on these two steps
thing tool that may be used
compile'com.tencent. mm.opensdk: WeChat Android-SDK-with-MTA-: + '
the compile (' com.thoughtworks.xstream: XStream: 1.4.7 ') {
excludegroup:' XMLPull ', Module1:' XMLPull '
}
compile'com.zhy : okhttputils: 2.4.1 '
second, if you do not want to fight, then the tool is inside of XML XML parser generators
have time to give you explain some OKHttp underlying RXJAVA, Kotlin, Android source code,
refueling, 0.0 Haha.
0.0 **

Guess you like

Origin blog.csdn.net/qq_31392539/article/details/93721002
Recommended