zoukankan      html  css  js  c++  java
  • ionic-cordova 微信支付插件

    cordova-plugin-wechat

    A cordova plugin, a JS version of Wechat SDK

    Feature

    Share title, description, image, and link to wechat moment(朋友圈)

    Example

    See cordova-plugin-wechat-example

    Install

    1. cordova plugin add cordova-plugin-wechat --variable wechatappid=YOUR_WECHAT_APPID, or using plugman, phonegap, ionic

    2. cordova build ios or cordova build android

    3. (iOS only) if your cordova version <5.1.1,check the URL Type using XCode

    Usage

    Check if wechat is installed

    Wechat.isInstalled(function (installed) {
        alert("Wechat installed: " + (installed ? "Yes" : "No"));
    }, function (reason) {
        alert("Failed: " + reason);
    });

    Authenticate using Wechat

    var scope = "snsapi_userinfo",
        state = "_" + (+new Date());
    Wechat.auth(scope, state, function (response) {
        // you may use response.code to get the access token.
        alert(JSON.stringify(response));
    }, function (reason) {
        alert("Failed: " + reason);
    });

    Share text

    Wechat.share({
        text: "This is just a plain string",
        scene: Wechat.Scene.TIMELINE   // share to Timeline
    }, function () {
        alert("Success");
    }, function (reason) {
        alert("Failed: " + reason);
    });

    Share media(e.g. link, photo, music, video etc)

    Wechat.share({
        message: {
            title: "Hi, there",
            description: "This is description.",
            thumb: "www/img/thumbnail.png",
            mediaTagName: "TEST-TAG-001",
            messageExt: "这是第三方带的测试字段",
            messageAction: "<action>dotalist</action>",
            media: "YOUR_MEDIA_OBJECT_HERE"
        },
        scene: Wechat.Scene.TIMELINE   // share to Timeline
    }, function () {
        alert("Success");
    }, function (reason) {
        alert("Failed: " + reason);
    });

    Share link

    Wechat.share({
        message: {
            ...
            media: {
                type: Wechat.Type.WEBPAGE,
                webpageUrl: "http://tech.qq.com/zt2012/tmtdecode/252.htm"
            }
        },
        scene: Wechat.Scene.TIMELINE   // share to Timeline
    }, function () {
        alert("Success");
    }, function (reason) {
        alert("Failed: " + reason);
    });

    Send payment request

    // See https://github.com/xu-li/cordova-plugin-wechat-example/blob/master/server/payment_demo.php for php demo
    var params = {
        partnerid: '10000100', // merchant id
        prepayid: 'wx201411101639507cbf6ffd8b0779950874', // prepay id
        noncestr: '1add1a30ac87aa2db72f57a2375d8fec', // nonce
        timestamp: '1439531364', // timestamp
        sign: '0CB01533B8C1EF103065174F50BCA001', // signed string
    };
    
    Wechat.sendPaymentRequest(params, function () {
        alert("Success");
    }, function (reason) {
        alert("Failed: " + reason);
    });


    原文链接:https://github.com/xu-li/cordova-plugin-wechat
  • 相关阅读:
    IoC~MVC3+EF+Autofac实现松耦合的系统架构 [转载]
    Ioc容器Autofac系列 向导
    依赖注入框架Autofac的简单使用 转载
    学 Win32 汇编[30] 条件及循环伪指令: .IF、.WHILE、.REPEAT 等
    学 Win32 汇编[31] 结构与联合
    在 API 函数中使用 PChar 参数的几种方法
    关于 "高位" 与 "低位" 回复 "Lovemit" 的问题
    如何把类中的方法做参数 回复 "林Lin☆☆" 的问题
    一个拼图工具的制作思路 回复 "AlwaysBug" 的问题
    简单的 "双缓冲" 绘图的例子 回复 "TookiQ" 的问题
  • 原文地址:https://www.cnblogs.com/qifan/p/6409226.html
Copyright © 2011-2022 走看看