|
最近使用ionic开发一个app,项目需求加入微信支付功能,网上找了一个集成插件
https://github.com/xu-li/cordova-plugin-wechat
安装成功,JS代码如下
- .controller('RecommendCtrl', function ($scope,PayService) {
- $scope.wxpaytest= function () {
- try {
- PayService.getJson().then(function(data){
- if(data){
- if(data.result=="0"){
- var json = {
- appid: data.appid,
- noncestr: data.noncestr,
- package: data.package,
- partnerid: data.partnerid,
- prepayid: data.prepayid,
- timestamp: data.timestamp,
- sign: data.sign
- }
- PayService.newtime(json);
- } else{
- alert("失败了");
- }
- }
- });
- }catch(ex){
- alert(ex);
- }
- }
- }
- .factory("PayService",function($q,$http){
- return {
- getJson: function()
- {
- var r = $q.defer();
- $http.get("http://192.168.1.231:8082/invoice_web/webInterface/selectByPname.html?pid=&pname=%E4%B9%89%E4%B9%8C&productName=%E4%B9%89%E4%B9%8C&sign=E43202ADE0A913E8&uid=7a21294f-d8c0-432b-b327-10ddb53f3e79").success(function (data) {
- r.resolve(data);
- }).error(function (er) {
- r.resolve(!1);
- });
- return r.promise;
- },
- newtime:function(json){
- wxpay.payment(json, function(msg){
- var json =JSON.parse(msg);
- if(json.code==0){
- alert("支付成功返回页面");
- }
- }, function(error){
- var json =JSON.parse(error);
- if(json.code ==-2){
- alert("用户不支付了,点击取消,返回APP");
- }
- })
- }
- }
- })
复制代码
html代码如下- <div class="item" ng-click="wxpaytest()">微信支付</div>
复制代码
运行结果如下:
|
|