-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodeek.rss.xml
More file actions
244 lines (202 loc) · 19.7 KB
/
codeek.rss.xml
File metadata and controls
244 lines (202 loc) · 19.7 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Codeek</title><link>http://codeek.github.io/</link><description></description><atom:link href="http://codeek.github.io/feeds/codeek.rss.xml" rel="self"></atom:link><lastBuildDate>Sun, 06 Dec 2015 00:00:00 +0800</lastBuildDate><item><title>ListView基本用法总结</title><link>http://codeek.github.io/listviewji-ben-yong-fa-zong-jie.html</link><description><h5 id="listview">ListView之我所见</h5>
<p>如今安卓App中最常见的控件应该就是ListView了,联系人和短信列表都是ListView实现的.作为安卓学习之路上的一个重量级的boss,今天算是初步的学习了它的相关知识,以下为今日学习的内容.</p>
<h4 id="_1">主要流程</h4>
<div class="codehilite" style="background: #f8f8f8"><pre style="line-height: 125%">创建实体类,定义自定义布局文件
自定义适配器类,重写其中关键方法
</pre></div>
<h5 id="_2">主要代码</h5>
<p><code>PersonBean</code></p>
<div class="codehilite" style="background: #f8f8f8"><pre style="line-height: 125%">private String name;
private Integer headPhoto;
public PersonBean(String name, Integer headPhoto) {
this.name = name;
this.headPhoto = headPhoto;
}
//getter&amp;setter
</pre></div>
<p><code>PersonAdapter</code> </p>
<div class="codehilite" style="background: #f8f8f8"><pre style="line-height: 125%">private int resourceId;
private String TAG = &quot;PersonAdapter&quot;;
public PersonAdapter(Context context, int resource, List&lt;PersonBean&gt; objects) {
super(context, resource, objects);
resourceId = resource;
}
/****
* 重写了 getView()方法,这个方法在每个子项被滚动到屏幕内的时候 会被调用。
* 在 getView 方法中,首先通过 getItem()方法得到当前项的 Fruit 实例,然后使用 LayoutInflater 来为这个子项加载我们传入的布局
* 接着调用 View 的 findViewById()方法分别 获取到 ImageView 和 TextView 的实例
* 并分别调用它们的 setImageResource()和 setText()方法来设置显示的图片和文字
* 最后将布局返回,这样我们自定义的适配器就完成了
*
* @param position 没一个item的下标
* @param convertView
* @param parent
* @return
*/
@Override
public View getView(int position, View convertView, ViewGroup parent) {
//获取当前的person
Log.d(TAG, &quot;position:&quot; + position);
PersonBean personBean = getItem(position);
View view = LayoutInflater.from(getContext()).inflate(resourceId, null);
ImageView imageView = (ImageView) view.findViewById(R.id.head_photo);
TextView textView = (TextView) view.findViewById(R.id.user_name);
imageView.setImageResource(personBean.getHeadPhoto());
textView.setText(personBean.getName());
return view;
}
</pre></div>
<p><code>ListViewActivity</code> </p>
<div class="codehilite" style="background: #f8f8f8"><pre style="line-height: 125%"> PersonAdapter personAdapter = new PersonAdapter(ListViewActivity.this, R.layout.person, personBeanList);
ListView listView = (ListView) findViewById(R.id.list_view);
listView.setAdapter(personAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
Toast.makeText(ListViewActivity.this, personBeanList.get(position).getName(), Toast.LENGTH_SHORT).show();
}
});
</pre></div>
<p><strong>效果图如下所示:</strong></p>
<p><img alt="alt text" src="https://lh3.googleusercontent.com/-1Y3erTDrRqE/Vmbf5Jk12mI/AAAAAAAABQo/4fFtLJ9IKrQ/s512-Ic42/listview.jpg" title="效果图" /> </p></description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Codeek</dc:creator><pubDate>Sun, 06 Dec 2015 00:00:00 +0800</pubDate><guid>tag:codeek.github.io,2015-12-06:listviewji-ben-yong-fa-zong-jie.html</guid><category>Android学习笔记</category></item><item><title>支付相关的关键代码以及注意点整理</title><link>http://codeek.github.io/zhi-fu-xiang-guan-de-guan-jian-dai-ma-yi-ji-zhu-yi-dian-zheng-li.html</link><description><h3 id="_1">市面上主流的第三方支付方式</h3>
<p>现在最主流的第三方支付方式应该是支付宝,微信支付,还有银联支付这三种,非主流的还有比如京东支付,以及下文需要提到的连连支付,电信公司的翼支付等等.前段时间的项目中用到了微信支付还有连连支付,翼支付这些小众的支付方式,个人觉得后面这两种支付方式略微奇葩,用的人真心少,然并卵,客户是老大,给钱的是大爷,所以只能吐槽一下,该写的代码还是要写,该读的文档还是要读.PS:本文所分享的微信支付以及其余支付都是针对<strong>APP支付,并且是服务端的代码</strong>,如果接下来的项目中会用到例如<strong>微信公众号支付</strong>,<strong>Js支付</strong>时会补充该文.</p>
<h3 id="_2">支付大体流程概述</h3>
<p><strong>做了这三种支付,个人感觉支付大体流程都是相同的,如下:</strong></p>
<div class="codehilite" style="background: #f8f8f8"><pre style="line-height: 125%">1.App调用后台接口,传入第三方支付所需要的必要参数,服务端进行数据校验,确保数据真实性
2.服务端获得App传递的参数,按照第三方支付的要求进行数据加签或者比如微信需要服务端主动请求微信服务器先获得预支付订单号,服务端进行数据入库
3.服务端将处理好的必要的支付参数传递给App端,App调用第三方SDK进行支付
</pre></div>
<p>要说有区别的就是传参类型,回调接口传参方式不一样而已,我们需要注意的是如何保证自己系统的业务数据状态正常,还有就是安全问题,因为前段时间的项目被人攻击了,而自己写的代码严谨性不够,导致...........哎,记录下来留作警示吧.</p>
<h3 id="app">微信APP支付步骤以及关键代码</h3>
<p>无论做哪一种第三方支付,研读它的文档对于开发人员来说都是必须的,所以阅读第三方文档的能力对于IT这一行来说是至关重要的.
<a href="https://pay.weixin.qq.com/wiki/doc/api/app.php?chapter=9_1" title="微信支付官方文档">微信支付官方文档</a></p>
<p>读过App支付相关章节我们可以发现,微信支付首先需要服务端主动请求微信服务器,获取此次支付的预支付订单号,并且说明了选传必传的参数,下面只列出必传的参数,具体参数含义请阅读官方文档<strong>统一下单章节</strong>:</p>
<div class="codehilite" style="background: #f8f8f8"><pre style="line-height: 125%">1.appid 公众账号ID
2.mch_id 商户号
3.nonce_str 随机字符串
4.sign 签名
5.body 商品描述
6.out_trade_no 商户订单号
7.total_fee 总金额(单位为分)
8.spbill_create_ip 终端IP
9.notify_url 通知地址
10.trade_type 交易类型
</pre></div>
<p>sign需要服务端将上面的参数按照字典表进行排序,组成如下的形式:</p>
<div class="codehilite" style="background: #f8f8f8"><pre style="line-height: 125%">appid=XXX&amp;body=XXX&amp;mch_id=XXX......
</pre></div>
<p>接下来我们需要使用上一步组装好的字符串最后加上微信提供给你的appkey,假设上一步获得的字符串名称为paramStr:</p>
<div class="codehilite" style="background: #f8f8f8"><pre style="line-height: 125%">paramStr&amp;key=YourAppKeyValue
</pre></div>
<p>最后我们将上面的字符串进行32位MD5加密并且转大写得到最终sign参数的值.最后将sign与上面所说的必填参数组装成xml文件发送给微信服务器,官方示例:</p>
<div class="codehilite" style="background: #f8f8f8"><pre style="line-height: 125%">&lt;xml&gt;
&lt;appid&gt;xxx&lt;/appid&gt;
&lt;attach&gt;支付测试&lt;/attach&gt;
&lt;body&gt;APP支付测试&lt;/body&gt;
&lt;mch_id&gt;xxx&lt;/mch_id&gt;
&lt;nonce_str&gt;xxxx&lt;/nonce_str&gt;
&lt;notify_url&gt;xxx&lt;/notify_url&gt;
&lt;out_trade_no&gt;xxxx&lt;/out_trade_no&gt;
&lt;spbill_create_ip&gt;127.0.0.1&lt;/spbill_create_ip&gt;
&lt;total_fee&gt;1&lt;/total_fee&gt;
&lt;trade_type&gt;APP&lt;/trade_type&gt;
&lt;sign&gt;xxxx&lt;/sign&gt;
&lt;/xml&gt;
</pre></div>
<p>上述步骤的工具类以及http请求的代码这里就不分享了吧,实现起来很简单.请求发送过去之后,如果上述步骤中的参数没有错误的话,微信会返回给服务端一串xml,我们只需要获取其节点中的<strong>prepay_id</strong>字段的值,再参照文档中的<strong>调起支付接口章节</strong>中的必传参数列表:</p>
<div class="codehilite" style="background: #f8f8f8"><pre style="line-height: 125%">1.appid 公众账号ID
2.partnerid 商户号
3.prepayid 预支付交易会话ID
4.package 暂填写固定值Sign=WXPay
5.noncestr 随机字符串
6.timestamp 时间戳
7.sign 签名
</pre></div>
<p>这个接口中的sign的生成方法和<strong>统一下单接口</strong>方式一样.</p>
<p>最后我们将<strong>调起支付接口</strong>中的参数传递给App端,App端的开发人员参照APP SDK开发文档使用服务器端传递的参数调起微信支付.</p>
<p>App端支付成功之后,会有同步回调通知与异步回调通知,后台开发人员只关心异步回调通知,异步回调地址是我们在<strong>统一下单章节</strong>中参数notify_url所决定的.</p>
<p>这里需要吐槽微信官方的是,官方文档中只写了返回的字段名称以及含义,并没有说明是以何种方式返回的,最后是通过debug的方式确定返回的方式,代码如下:</p>
<div class="codehilite" style="background: #f8f8f8"><pre style="line-height: 125%">StringBuffer sb = new StringBuffer();
InputStream is = request.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String s = &quot;&quot;;
while ((s = br.readLine()) != null) {
sb.append(s);
}
logger.info(&quot;******微信回调通知内容*****&quot; + sb.toString());
</pre></div>
<p>处理回调方法的时候需要注意的是需要对回调的内容<strong>进行验签处理</strong>,防止别人伪造数据,比如:实际支付了一分钱,随后伪造微信通知,而你收到通知如果不做校验继续执行了类似于充值的业务,损失就大了.</p></description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Codeek</dc:creator><pubDate>Fri, 27 Nov 2015 00:00:00 +0800</pubDate><guid>tag:codeek.github.io,2015-11-27:zhi-fu-xiang-guan-de-guan-jian-dai-ma-yi-ji-zhu-yi-dian-zheng-li.html</guid><category>支付相关</category></item><item><title>安卓Activity基本用法总结</title><link>http://codeek.github.io/an-zhuo-activityji-ben-yong-fa-zong-jie.html</link><description><h4 id="intentactivity">Intent跳转Activity方式</h4>
<p>1.<strong>显式跳转以及传值</strong></p>
<p>MainActivity关键代码 </p>
<div class="codehilite" style="background: #f8f8f8"><pre style="line-height: 125%">Intent startActIntent = new Intent(MainActivity.this, ThirdActivity.class);
startActIntent.putExtra(&quot;name&quot;, &quot;peter&quot;);
startActIntent.putExtra(&quot;sex&quot;, &quot;male&quot;);
startActivity(startActIntent);
</pre></div>
<p>ThirdActivity关键代码</p>
<div class="codehilite" style="background: #f8f8f8"><pre style="line-height: 125%"> //接收从FirstActicity传入的参数
Intent valueIntent = getIntent();
showText.setText(valueIntent.getStringExtra(&quot;name&quot;)+&quot;,&quot;+valueIntent.getStringExtra(&quot;sex&quot;));
</pre></div>
<p>2.<strong>隐式跳转</strong></p>
<p>MainActivity关键代码</p>
<div class="codehilite" style="background: #f8f8f8"><pre style="line-height: 125%">//此处设置的值为在AndroidManifest.xml中设置的SecondActivity的intent-filter中设置的action属性
Intent intent = new Intent(&quot;com.xt.firstapp.TEST_INTENT&quot;);
//如若不指定该category,则系统默认添加android.intent.category.DEFAULT
intent.addCategory(&quot;android.intent.category.DEFAULT&quot;);
startActivity(intent);
</pre></div>
<p>AndroidManifest关键代码</p>
<div class="codehilite" style="background: #f8f8f8"><pre style="line-height: 125%">&lt;activity android:name=&quot;.activity.SecondActivity&quot;&gt;
&lt;intent-filter&gt;
&lt;action android:name=&quot;com.xt.firstapp.TEST_INTENT&quot; /&gt;
&lt;category android:name=&quot;android.intent.category.DEFAULT&quot; /&gt;
&lt;/intent-filter&gt;
&lt;/activity&gt;
</pre></div>
<p>3.返回上一个Activity传递参数</p>
<p>MainActivity关键代码</p>
<div class="codehilite" style="background: #f8f8f8"><pre style="line-height: 125%"> Intent resultIntent = new Intent(MainActivity.this, SecondActivity.class);
//requestcode设置为1
startActivityForResult(resultIntent, 1);
//如果要从上一个返回activity取得数据,则需要覆写该方法
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case 1:
if (RESULT_OK == resultCode) {
Log.d(&quot;back_data-----&quot;, data.getStringExtra(&quot;back_data&quot;));
Toast.makeText(MainActivity.this, data.getStringExtra(&quot;back_data&quot;), Toast.LENGTH_LONG).show();
}
}
}
</pre></div>
<p>SecondActivity关键代码</p>
<div class="codehilite" style="background: #f8f8f8"><pre style="line-height: 125%">Intent backIntent=new Intent();
backIntent.putExtra(&quot;back_data&quot;, &quot;this is back data from second activity&quot;);
setResult(RESULT_OK, backIntent);
finish();
</pre></div>
<p>4.Intent除了跳转之外另外的用法</p>
<div class="codehilite" style="background: #f8f8f8"><pre style="line-height: 125%">//Intent打开浏览器
Intent viewIntent = new Intent(Intent.ACTION_VIEW);
viewIntent.setData(Uri.parse(&quot;https://www.baidu.com&quot;));
startActivity(viewIntent);
//Intent拨打电话
Intent dialIntent = new Intent(Intent.ACTION_DIAL);
dialIntent.setData(Uri.parse(&quot;tel:10086&quot;));
startActivity(dialIntent);
</pre></div></description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Codeek</dc:creator><pubDate>Thu, 26 Nov 2015 00:00:00 +0800</pubDate><guid>tag:codeek.github.io,2015-11-26:an-zhuo-activityji-ben-yong-fa-zong-jie.html</guid><category>Android学习笔记</category></item><item><title>如梦初醒</title><link>http://codeek.github.io/ru-meng-chu-xing.html</link><description><h3 id="_1">圆梦</h3>
<hr />
<p>敲下第一行字,才想起距离写博客这个想法已经过了差不多一年时间.中间由于各种原因,一直未付诸于行动,直到今天,才算是正式破土动工,也算是圆了一直以来的一个<strong>梦想</strong>.</p>
<h3 id="_2">回忆</h3>
<hr />
<p>第一次接触博客记忆之中应该是在<strong>大学</strong>求学期间,当时也是很佩服他的,从大一上学期开始就已经开始学习js了,光不说自学的效果如何,至少别人起步就比我们这些还沉浸在娱乐之中的人快了许多.随后的一段时间也见到他开通了自己的博客,弄了许多好玩的东西.自己当时对技术也是不怎么感兴趣的,只是单纯的佩服而已,到了大一下学期那会,安卓手机的流行,激发了我对刷机的兴趣,随后的一年多的时间里,自己对于刷机处于着迷的状态,基本上每天都会拿自己或同学的手机捣鼓到很久,逐渐成为了小有名声的刷机达人(羞涩....),也是从那时候开始,才逐渐明白技术的重要性,也逐渐的对安卓产生了兴趣,但在那时还没有上升到写代码的程度. </p>
<p>因为安卓程序是由java写的,所以大二下学期开始便开始了苦逼的<strong>自学java</strong>历程,基本上每天除了上课就是写代码,虽然有些夸张,但却是真实的写照.随后的日子里,将书中的例子敲了个遍,再加上教学视频中老师所说的编程先从别人的代码中学习,摸索并发展出自己的思想,如果没有自己的思想就真的要变成了码农,不过在没有人指导的那个年代,以及身边无人有学习的欲望的时候,你会突然的发现自己是多么的孤独,但是,耐得住寂寞的才会成功,这话在毕业的时候才会深有感触,先且不谈工作有多舒服,至少是让父母在工作这方面不用操心.</p>
<h3 id="_3">工作</h3>
<hr />
<p>从14年六月份毕业至今也有一年多的时间了,一直都在做<strong>JAVA WEB</strong>开发.去年基本上是在每天加班中度过的,虽然很忙,但是自己却过得很充实,干劲十足.所以在别人眼中很苦逼的,自己却一点都不觉得有多辛苦.如果现在让我说一种自己选择这种工作的原因,我想首当其冲的应该要感谢编程给自己打来的成就感,这是一种促使自己前进的动力,所以在工作中保持这种源源不断的成就感是很重要的.</p>
<p>自己目前的状态,能够快速上手目前市面上所流行的框架,以及快速接入与使用第三方API.众所周知,中国的IT产业基本上都是业务类型的,程序员所要处理的最多的无非就是<strong>CRUD</strong>操作,所以大部分要做的主要就是将业务熟悉,接下来写代码的事都好办.所幸的是我司项目并不那么单调,除了业务也有许多很有意思的东西.</p>
<p>举个例子,差不多是在去年的这个时候,我司有项目要用到推送的功能,于是项目经理要求我自己将百度推送相关文档研究一下.对于初出茅庐的我当时可是第一次尝试使用第三方<strong>API</strong>,既兴奋也忐忑.<strong>兴奋</strong>是由于前段时间也做了几个月的业务,现在能接第一次接触到自己没碰过的东西,自然而然会很兴奋.<strong>忐忑</strong>也是很容易理解的,因为是<strong>首次</strong>接触,难免会有一些担心.庆幸的是,最终还是很顺利的完成了这个任务.</p></description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Codeek</dc:creator><pubDate>Thu, 19 Nov 2015 00:00:00 +0800</pubDate><guid>tag:codeek.github.io,2015-11-19:ru-meng-chu-xing.html</guid><category>生活</category></item></channel></rss>