npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pi_sso_sdk

v1.0.41

Published

## 单点登录流程

Downloads

1

Readme

pi_sso_sdk

单点登录流程

  1. 获取sdk单例
  • 旧版SDK
import { getSdkContext } from 'pi_sso_sdk/sdk/index';
Global.sdk = await getSdkContext();
// 登录类型 LoginType 应导入 'pi_sso_sdk/sso/sso_client'
  • 新版SDK
import { getNewSdkContext } from 'pi_sso_sdk/sdk/new_index';
Global.sdk = await getNewSdkContext();
// 登录类型 LoginType 应导入 'pi_sso_sdk/sso/new_sso_client'
  1. 设置单点登录的服务器
let { host, port, isTls } = PISYS.Env.get('platform_server').default;
Global.sdk.login.setServer(host, port, isTls);
  1. 设置是否保存和使用登录凭证
Global.sdk.login.saveAuth(true);
Global.sdk.login.useLastAuth(true);
  1. 设置登录和登出的回调
// 登录
Global.sdk.login.onLogin((info, fail) => {
    if (fail) {
        logW("login fail, reason = %o", fail);
    } else {
        logD("login success, sdkName = %s", info.sdkName);

        // 开始授权 登录成功后立即授权,一定不会失败
        Global.sdk.login.getAuth().then(auth => {
            logD("auth success,auth = %o", auth);
            // TODO 创建网络连接
        })
    }
});
// 登出
Global.sdk.login.onLogout((info, fail) => {
    if (fail) {
        logE("logout failed, reason = %o", fail);
    } else {
        logD("logout success, sdkName = %s" + info.sdkName);

        // 清除凭证,具体说明看 注释
        Global.sdk.login.clearAuth();
    }
});
  1. 如果允许使用登录凭证,则直接执行获取授权
// 获取授权,已登录过会保存信息,直接可授权成功
Global.sdk.login.getAuth().then(auth => {
    logD("auto success, auth = %o", auth);
    // TODO 创建网络连接
}).catch(e => {
    logW("auto failed, reason = %o", e);
});
  1. 执行登录,登录成功后第4步注册的回调会被执行
Global.sdk.login.login({
    loginType: LoginType.VISITORS, // 游客登录
})

Global.sdk.login.login({
    loginType: LoginType.ACCOUNT, // 账号密码登录
    account: this.props.input1,
    pwd: this.props.input2,
    autoRegister: true  // 自动注册
})

支付流程

先执行完单点登录才可以支付

  1. 设置支付的服务器(一般与单点登录同一个服务器)
let { host, port, isTls } = PISYS.Env.get('platform_server').default;
Global.sdk.pay.setServer(host, port, isTls);
  1. 支付下单
// 参数 不同渠道有不同的需求
Global.sdk.pay.unifiedOrder({
    app: 'test',
    channel: PayChannelName.wx,
    amount: 100,
    currency: 'cny',
}).then((r) => {
    // TODO 下单成功 可支付
}).catch(() => {
    // 下单失败
})
  1. 支付
// r 是下单时返回的值
const info = JSON.parse(r.credential).info;
// 参数 不同渠道有不同的需求
Global.sdk.pay.pay({
    amount: 100,
    orderID: r.pt_oid,
    goodsID: '2',
    goodsDesc: 'test',
    goodsName: '测试',
    orderInfo: info,
    payment: PayType.wx,
}).then(() => {
    // TODO 支付成功 可查询订单
}).catch((e) => {
    // 支付失败
});
  1. 查询订单
  • 旧版SDK
// r 是下单时返回的值
Global.sdk.pay.queryOrder('test', r.pt_oid).then((order) => {
    logD('查询订单成功', order);
}).catch((err) => {
    logD('查询订单失败', err);
});
  • 新版SDK
    • 需要在服务器端写接口查询
    • 用游戏独有的私钥对数据签名
import { request } from "pi_pt/net_client/httpc";

// 支付平台
export const PRE_URL = 'https://sdktest.17youx.cn';
// 游戏私钥
export const PRIVATE_KEY = '0440990801123db1cfe33d43ca968d684f76e9f23b9dff885eacb94c9c896b38fba6259a275d0ef6e18464b9800193034d5cb90a1640a9b6190f118943a662137d'; 
// 查询订单
export const queryOrder = async (hash: string) => {
    let paramStr = jsonUriSort({ hash, appid: APP_ID })
    let gameSign = sign(paramStr, PRIVATE_KEY);
    let obj = {
        url: PRE_URL + '/api/pay/orderquery?' + paramStr + '&sign=' + gameSign,
        method: "GET"
    };
    console.log('pay queryOrder obj ======== ', obj);
    let r = await request(obj, true);
    console.log('pay queryOrder r ======== ', r);

    return r;
}
  1. 服务器端接收支付成功的推送 只推一次
import { verify } from "pi_pt/util/sign";

export const PUBLIC_KEY = '0440990801123db1cfe33d43ca968d684f76e9f23b9dff885eacb94c9c896b38fba6259a275d0ef6e18464b9800193034d5cb90a1640a9b6190f118943a662137d';

// 到账通知
// #[httpRpc=/port/notify]
export const payNotify = async (req: HttpRequest, _resp: HttpResponse) => {
    const data = req.getData();
    console.log('payNotify data ======== ', data);
    let sign = data.sign;
    delete data.sign;
    if (!verify(data, sign, PUBLIC_KEY)) return 'sign error';

    // TODO 处理订单信息
    return 'ok'
}

实名认证

先执行完单点登录才可以实名认证

  1. 设置实名认证服务器(一般与单点登录同一个服务器)
let { host, port, isTls } = PISYS.Env.get('platform_server').default;
Global.sdk.verify.setServer(host, port, isTls);
  1. 查询是否认证过
// app 服务器上为每个游戏配置时取得名字,例如ydzm
// uuid 单点登录成功后返回的用户唯一id
// force 是否严格模式 非严格模式仅验证了身份证号与名字不符的情况
sdk.verify.query(app, uuid, force).then(r => {
    if (r.return_code === '0') {
        // 已认证过
    } else {
        // 未认证过
    }
});
  1. 实名认证
// name 姓名  
// id 身份证号
sdk.verify.verify(app, uuid, name, id, force).then(r => {
    if (r.return_code === '0') {
        // 认证成功
    } else {
        // 认证失败 r.reason 中可查看原因
    }
});

后端BI上报

  1. 创建一个BISDK实体
  2. 调用内部方法,进行数据上报

敏感词过滤

  1. 支持qq游戏大厅