原文再续,书接上一回!上一期我介绍了接入支付宝的SDK,本文就来讲讲微信的SDK接入.还是那句话,官方的文档,我只能用一句话形容:一言难尽!本屌还是一如既往,把"恶心的东西"嚼碎了喂给各位宝吃.
一.前言
首先还是要集齐可以召唤神龙的法器,给大家一一列举一下:
1.appId: #应用Id
2.mchId: #商户号
3.mchSerialNo: #商户证书序列号
4. apiV3Key: #APIv3秘钥
5. privateKeyPath: apiclient_key.pem #商户API私钥路径
6. notifyUrl: #回调地址
这里还是给大家啰嗦几句吧:1和2这个没啥好说的,只要按照官方的说明书就可以完成绑定即可,记住是双向绑定.
4.配置v3秘钥按照这里来:配置v3Key
3和5证书秘钥按照这个来:获取证书秘钥
拿到这三分证书后,
商户证书获取方式,通过一下命令获取:openssl x509 -in apiclient_cert.pem -noout -serial
查看证书序列号
$ openssl x509 -in apiclient_cert.pem -noout -serial
serial=1xxxxxxxxxxxxxxxC
如图所示,会得到一串神秘字符,这就是商户证书序列号(我是maxOS操作的,windows自寻出路)
6.回调地址,这个就是给微信通知你的地址,也没啥好说的
二.支付流程
这里我就不再细说了,大宝们可以参考我上一篇:[CocosCreator]全栈接入阿里支付宝SDK
支付流程介绍,大同小异,只是参数不太一样罢了.
二.客户端接入(cocos creator)
1.老生常谈了,先打包构建:安卓工程
2.打开安卓工程,引入依赖
3.改写org/cocos2dx/javascript/AppActivity.java,这里我省略了一些没用的干扰方法,只保留微信支付需要的,如图:
/****************************************************************************
Copyright (c) 2015-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULA