super.onCreate(savedInstanceState);
ViewUtils.inject(this);
goods = new Goods();
goods.costprice=100;
goods.productid=692356222;
goods.producttypeid=11;
goods.productname=“测试商品”;
goods.discountprice=0.01;
goods.productdescription=“商品描述”;
goods.companydesc=“测试商户简单描述”;
goods.comanyadress=“商户地址未知”;
goods.companyname=“测试商户”;
goods.score=1;
goods.status=1;
goods.stock=300;
count=1;
initData();
initView();
}
private void initData() {
username =“客户名称”;
mobile = “13800380038”;
adress=“客户地址”;
}
private void initView() {
usernameTV.setText(“收货人:”+username);
phoneTV.setText(mobile+“”);
adressTV.setText(adress);
descTV.setText(goods.productdescription);
priceTV.setText(“¥”+goods.discountprice);
intgTV.setText(“积分:”+goods.score);
countTV1.setText(“X”+count);
countTV.setText(count+“”);
intgtotal1TV.setText(“共得到”+count*goods.score+“积分”);
intgtotal2TV.setText(“积分:”+count*goods.score);
counttotalTV.setText(“共”+count+“件”);
pricetotal1TV.setText(“¥”+Arith.mul(goods.discountprice, count));
pricetotal2TV.setText(“¥”+Arith.mul(goods.discountprice, count));
//ImageLoader.getInstance().displayImage(goods.pic1, img);
}
/**
-
增加数量
-
@param v
*/
@OnClick(R.id.product_ordsubmit_count_add)
public void add(View v) {
count++;
countTV1.setText(“X”+count);
countTV.setText(count+“”);
intgtotal1TV.setText(“共得到”+count*goods.score+“积分”);
intgtotal2TV.setText(“积分:”+count*goods.score);
counttotalTV.setText(“共”+count+“件”);
pricetotal1TV.setText(“¥”+Arith.mul(goods.discountprice, count));
pricetotal2TV.setText(“¥”+Arith.mul(goods.discountprice, count));
}
/**
-
减少数量
-
@param v
*/
@OnClick(R.id.product_ordsubmit_count_sub)
public void sub(View v) {
if (count>1) {
count–;
countTV1.setText(“X”+count);
countTV.setText(count+“”);
intgtotal1TV.setText(“共得到”+count*goods.score+“积分”);
intgtotal2TV.setText(“积分:”+count*goods.score);
counttotalTV.setText(“共”+count+“件”);
pricetotal1TV.setText(“¥”+Arith.mul(goods.discountprice, count));
pricetotal2TV.setText(“¥”+Arith.mul(goods.discountprice, count));
}
}
/**
-
提交订单
-
@param v
*/
@OnClick(R.id.product_ordsubmit_ok)
public void submit(View v) {
final OrderInfo orderInfo=new OrderInfo();
orderInfo.userid=13752;
orderInfo.areacode=23;
orderInfo.buildno=“10”;
orderInfo.roomno=“1001”;
orderInfo.producttypeid=goods.producttypeid;
orderInfo.productid=goods.productid;
orderInfo.amount=goods.discountprice;//单价
orderInfo.account=count;//数量
orderInfo.totalamount=Arith.mul(goods.discountprice, count);
//double offsetamount;//抵扣金额
orderInfo.score=count*goods.score;
//int assessitem;//评价项
//int assesslevel;//评价级别
//String assesscontent;//评价内容
//long payid=;//支付编号
orderInfo.status=2;//支付状态待付款
orderInfo.type=11;//日用品
orderInfo.usermemo =sayEt.getText().toString();//业主备注
orderInfo.address =adress;
orderInfo.productname =goods.productname;//
orderInfo.desccontext =goods.productdescription;//
orderInfo.outtradeno=System.currentTimeMillis()+“”+orderInfo.userid;
orderInfo.merchantid=goods.companyid;
submitorder(orderInfo);
}
/**
-
订单提交成功,进入付款界面
-
@param orderInfo
-
@return
*/
private void submitorder(OrderInfo orderInfo) {
Intent intent=new Intent(this, SelectPayTypeActivity.class);
intent.putExtra(“data”, orderInfo);
startActivity(intent);
}
}
(2)在mainactivty中点击确认按钮调用支付方式选择页面SelectPayTypeActivity,用来发起支付选择。
(3)根据支付方式调用对应工具类微信(WXpayUtil)
public class WXpayUtil {
private IWXAPI api;
private OrderInfo order;
private Context context;
private PayReq req;
private Map<string,string> resultunifiedorder;
private static final String TAG = “ewuye.online.SelectPayTypeActivity”;
public WXpayUtil(Context mcontext,OrderInfo order){
//初始化微信支付
this.order=order;
this.context=mcontext;
if (TextUtils.isEmpty(ParameterConfig.WX_APP_ID) || TextUtils.isEmpty(ParameterConfig.WX_MCH_ID) || TextUtils.isEmpty(ParameterConfig.WX_API_KEY)) {
new AlertDialog.Builder(context).setTitle(“警告”).setMessage(“需要配置WX_APP_ID | WX_MCH_ID| WX_API_KEY\n请到ParameterConfig.java里配置”)
.setPositiveButton(“确定”, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialoginterface, int i) {
//
((Activity)context).finish();
}
}).show();
return;
}
api = WXAPIFactory.createWXAPI(context, null);
req = new PayReq();
//生成prepay_id
GetPrepayIdTask getPrepayId = new GetPrepayIdTask();
getPrepayId.execute();
}
/**
-
用于获取
-
@author 95
*/
private class GetPrepayIdTask extends AsyncTask<void, string=“”>> {
private ProgressDialog dialog;
@Override
protected void onPreExecute() {
dialog = ProgressDialog.show(context, “提示”, “正在获取预支付订单…”);
}
@Override
protected void onPostExecute(Map<string,string> result) {
if (dialog != null) {
dialog.dismiss();
}
resultunifiedorder=result;
genPayReq();
}
@Override
protected void onCancelled() {
super.onCancelled();
}
@Override
protected Map<string,string> doInBackground(Void… params) {
String url = String.format(“https://api.mch.weixin.qq.com/pay/unifiedorder”);
String entity = genProductArgs();
Log.e(“orion”,entity);
byte[] buf = httpPost(url, entity);
String content = new String(buf);
Log.e(“orion”, content);
Map<string,string> xml=decodeXml(content);
return xml;
}
}
private void genPayReq() {
req.appId = ParameterConfig.WX_APP_ID;
req.partnerId = ParameterConfig.WX_MCH_ID;
req.prepayId = resultunifiedorder.get(“prepay_id”);
req.packageValue = “prepay_id=”+resultunifiedorder.get(“prepay_id”);
req.nonceStr = genNonceStr();
req.timeStamp = String.valueOf(genTimeStamp());
List signParams = new LinkedList();
signParams.add(new BasicNameValuePair(“appid”, req.appId));
signParams.add(new BasicNameValuePair(“noncestr”, req.nonceStr));
signParams.add(new BasicNameValuePair(“package”, req.packageValue));
signParams.add(new BasicNameValuePair(“partnerid”, req.partnerId));
signParams.add(new BasicNameValuePair(“prepayid”, req.prepayId));
signParams.add(new BasicNameValuePair(“timestamp”, req.timeStamp));
req.sign = genAppSign(signParams);
Log.e(“orion”, signParams.toString());
sendPayReq();
}
private void sendPayReq() {
api.registerApp(ParameterConfig.WX_APP_ID);
api.sendReq(req);
}
private String genProductArgs() {
StringBuffer xml = new StringBuffer();
try {
String nonceStr = genNonceStr();
xml.append(“”);
List packageParams = new LinkedList();
packageParams.add(new BasicNameValuePair(“appid”, ParameterConfig.WX_APP_ID));
packageParams.add(new BasicNameValuePair(“body”, order.productname));
packageParams.add(new BasicNameValuePair(“mch_id”, ParameterConfig.WX_MCH_ID));
packageParams.add(new BasicNameValuePair(“nonce_str”, nonceStr));
packageParams.add(new BasicNameValuePair(“notify_url”, ParameterConfig.WX_notifyUrl));
packageParams.add(new BasicNameValuePair(“out_trade_no”,genOutTradNo()));
packageParams.add(new BasicNameValuePair(“spbill_create_ip”,“127.0.0.1”));
packageParams.add(new BasicNameValuePair(“total_fee”, (int)(order.totalamount*100)+“”));
packageParams.add(new BasicNameValuePair(“trade_type”, “APP”));
String sign = genPackageSign(packageParams);
packageParams.add(new BasicNameValuePair(“sign”, sign));
String xmlstring =toXml(packageParams);
return new String(xmlstring.toString().getBytes(), “ISO8859-1”);
//return xmlstring;
} catch (Exception e) {
Log.e(TAG, "genProductArgs fail, ex = " + e.getMessage());
return null;
}
}
private String genAppSign(List params) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < params.size(); i++) {
sb.append(params.get(i).getName());
sb.append(‘=’);
sb.append(params.get(i).getValue());
sb.append(‘&’);
}
sb.append(“key=”);
sb.append(ParameterConfig.WX_API_KEY);
String appSign = getMessageDigest(sb.toString().getBytes());
Log.e(“orion”,appSign);
return appSign;
}
private HttpClient getNewHttpClient() {
try {
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null, null);
SSLSocketFactory sf = new SSLSocketFactoryEx(trustStore);
sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme(“http”, PlainSocketFactory.getSocketFactory(), 80));
registry.register(new Scheme(“https”, sf, 443));
ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
return new DefaultHttpClient(ccm, params);
} catch (Exception e) {
return new DefaultHttpClient();
}
}
private class SSLSocketFactoryEx extends SSLSocketFactory {
SSLContext sslContext = SSLContext.getInstance(“TLS”);
public SSLSocketFactoryEx(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
super(truststore);
TrustManager tm = new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return null;
}
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType) throws java.security.cert.CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType) throws java.security.cert.CertificateException {
}
};
sslContext.init(null, new TrustManager[] { tm }, null);
}
@Override
public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException, UnknownHostException {
return sslContext.getSocketFactory().createSocket(socket, host, port, autoClose);
}
@Override
public Socket createSocket() throws IOException {
return sslContext.getSocketFactory().createSocket();
}
}
public byte[] httpPost(String url, String entity) {
if (url == null || url.length() == 0) {
Log.e(TAG, “httpPost, url is null”);
return null;
}
HttpClient httpClient = getNewHttpClient();
HttpPost httpPost = new HttpPost(url);
try {
httpPost.setEntity(new StringEntity(entity));
httpPost.setHeader(“Accept”, “application/json”);
httpPost.setHeader(“Content-type”, “application/json”);
HttpResponse resp = httpClient.execute(httpPost);
if (resp.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
Log.e(TAG, "httpGet fail, status code = " + resp.getStatusLine().getStatusCode());
return null;
}
return EntityUtils.toByteArray(resp.getEntity());
} catch (Exception e) {
Log.e(TAG, "httpPost exception, e = " + e.getMessage());
e.printStackTrace();
return null;
}
}
private String genOutTradNo() {
Random random = new Random();
return getMessageDigest(String.valueOf(random.nextInt(10000)).getBytes());
}
public Map<string,string> decodeXml(String content) {
try {
Map<string, string=“”> xml = new HashMap<string, string=“”>();
XmlPullParser parser = Xml.newPullParser();
parser.setInput(new StringReader(content));
int event = parser.getEventType();
while (event != XmlPullParser.END_DOCUMENT) {
String nodeName=parser.getName();
switch (event) {
case XmlPullParser.START_DOCUMENT:
break;
case XmlPullParser.START_TAG:
if(“xml”.equals(nodeName)==false){
//实例化student对象
xml.put(nodeName,parser.nextText());
}
break;
case XmlPullParser.END_TAG:
break;
}
event = parser.next();
}
return xml;
} catch (Exception e) {
Log.e(“orion”,e.toString());
}
return null;
}
private String genNonceStr() {
Random random = new Random();
return getMessageDigest(String.valueOf(random.nextInt(10000)).getBytes());
}
private long genTimeStamp() {
return System.currentTimeMillis() / 1000;
}
public String getMessageDigest(byte[] buffer) {
char hexDigits[] = { ‘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();
int j = md.length;
char str[] = new char[j * 2];
int k = 0;
for (int i = 0; i < j; i++) {
byte byte0 = md[i];
str[k++] = hexDigits[byte0 >>> 4 & 0xf];
str[k++] = hexDigits[byte0 & 0xf];
}
return new String(str);
} catch (Exception e) {
return null;
}
}
/**
生成签名
*/
private String genPackageSign(List params) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < params.size(); i++) {
sb.append(params.get(i).getName());
sb.append(‘=’);
sb.append(params.get(i).getValue());
sb.append(‘&’);
}
sb.append(“key=”);
sb.append(ParameterConfig.WX_API_KEY);
String packageSign = getMessageDigest(sb.toString().getBytes()).toUpperCase();
Log.e(“orion”,packageSign);
return packageSign;
}
private String toXml(List params) {
StringBuilder sb = new StringBuilder();
sb.append(“”);
for (int i = 0; i < params.size(); i++) {
sb.append(“<”+params.get(i).getName()+“>”);
sb.append(params.get(i).getValue());
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则近万的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Android)
学习交流
群内有许多来自一线的技术大牛,也有在小厂或外包公司奋斗的码农,我们致力打造一个平等,高质量的Android交流圈子,不一定能短期就让每个人的技术突飞猛进,但从长远来说,眼光,格局,长远发展的方向才是最重要的。
35岁中年危机大多是因为被短期的利益牵着走,过早压榨掉了价值,如果能一开始就树立一个正确的长远的职业规划。35岁后的你只会比周围的人更值钱。
《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!
天花板技术停滞不前!**
因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
[外链图片转存中…(img-iU7DTKhq-1713770499580)]
[外链图片转存中…(img-AJM4tGlj-1713770499582)]
[外链图片转存中…(img-1PLlEFov-1713770499583)]
[外链图片转存中…(img-W9V01pzi-1713770499586)]
[外链图片转存中…(img-BIKmJ0Mk-1713770499587)]
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Android)
[外链图片转存中…(img-yoLn7Ch7-1713770499589)]
学习交流
[外链图片转存中…(img-77Sq35bh-1713770499590)]
[外链图片转存中…(img-VfdgidfN-1713770499592)]
群内有许多来自一线的技术大牛,也有在小厂或外包公司奋斗的码农,我们致力打造一个平等,高质量的Android交流圈子,不一定能短期就让每个人的技术突飞猛进,但从长远来说,眼光,格局,长远发展的方向才是最重要的。
35岁中年危机大多是因为被短期的利益牵着走,过早压榨掉了价值,如果能一开始就树立一个正确的长远的职业规划。35岁后的你只会比周围的人更值钱。
《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!