子商户渠道参数
接入 Ping++ 子商户应用接口,仅需要 Ping++ Server SDK 即可。服务器端需要做的就是向 Ping++ 请求创建 Channel 对象,具体步骤如下:
- 设置 API-Key
- SDK 验证签名设置
- 从服务端发起创建子商户渠道参数请求,获取 Channel 对象
第一步:设置 API-Key
Ping++ API 交易时需要设置 API-Key,Server SDK 提供了设置的方法。如果你直接使用 API ,需要在 header 中加入 Authorization,格式是 Authorization: Bearer API-Key。
\Pingpp\Pingpp::setApiKey('sk_test_ibbTe5jLGCi5rzfH4OqPW9KC');
Pingpp.apiKey = "sk_test_ibbTe5jLGCi5rzfH4OqPW9KC";
var pingpp = require('pingpp')('sk_test_ibbTe5jLGCi5rzfH4OqPW9KC');
pingpp.api_key = 'sk_test_ibbTe5jLGCi5rzfH4OqPW9KC'
Pingpp.api_key = "sk_test_ibbTe5jLGCi5rzfH4OqPW9KC"
pingpp.Key = "sk_test_ibbTe5jLGCi5rzfH4OqPW9KC"
Pingpp.Pingpp.SetApiKey("sk_test_ibbTe5jLGCi5rzfH4OqPW9KC");
第二步:SDK 验证签名设置
为了进一步增强交易请求的安全性,Ping++ 交易接口针对所有的 POST 和 PUT 请求已经新增 RSA 加密验签功能。如果使用该签名验证功能,你需要生成密钥,然后将私钥配置到你的代码中,公钥上传至 Ping++ 管理平台并启用验签开关。首先你需要本地生成 RSA 公钥和私钥,生成方法请参考:如何获取 RSA 公钥和私钥?
设置请求签名密钥
你需要在代码中设置请求签名的私钥(rsa_private_key.pem),可以读取配置私钥文件的路径或者直接定义变量。你如果通过 API 接口校验的话,需要生成 RSA 签名(SHA256)并在请求头中添加 Pingplusplus-Signature,如果使用 SDK 的话只需要配置私钥即可。
\Pingpp\Pingpp::setPrivateKeyPath(__DIR__ . '/your_rsa_private_key.pem');
Pingpp.privateKeyPath = "/path/to/your_rsa_private_key.pem";
pingpp.setPrivateKeyPath(__dirname + "/your_rsa_private_key.pem");
pingpp.private_key_path = 'your_rsa_private_key.pem'
Pingpp.private_key_path = File.dirname(__FILE__) + '/your_rsa_private_key.pem'
privateKey, err := ioutil.ReadFile("your_rsa_private_key.pem")
Pingpp.Pingpp.SetPrivateKeyPath(@"../../your_rsa_private_key.pem");
上传公钥至 Ping++ 管理平台
设置完代码中的私钥,你需要将已经生成的公钥(rsa_public_key.pem)填写到 Ping++ 管理平台上。 配置路径: 登录 Ping++ 管理平台->点击右上角公司名称->企业面板->开发参数->商户 RSA 公钥->将你的公钥复制粘贴进去并且保存->先启用 Test 模式进行测试->测试通过后启用 Live 模式
注意: 一旦上传公钥至 Ping++ 管理平台并启用 Live 模式,则验证签名功能即时生效,Ping++ 会立即验证你的真实线上交易验签请求。如果私钥为空或错误,则会交易失败,所以请确保测试模式正常后再启用 Live 开关。
第三步:从服务端发起创建子商户渠道参数请求,获取 Channel 对象
调用 Ping++ Server SDK 发起创建请求。
$sub_app_channel = \Pingpp\Channel::create('app_1Gqj58ynP0mHeX1q', [ 'channel' => 'alipay', 'params' => [ 'fee_rate' => 60, 'alipay_pid' => '2088501666666666', 'alipay_account' => 'account@example.com', 'alipay_security_key' => 'Your security_key', 'alipay_mer_app_private_key' => '-----BEGIN RSA PRIVATE KEY-----MIICXQIBAAKBgQDSBOW3jdgyhyhygNJ8P+BQnfoKpL29BtvACW1gr8YhXh8EqpBUnUDdQgi8uYnprXBbR5O1DVnIqLKG9loEn3Rc2iqpnj3M3nSShuVByjyJjQ+DAIG2/cgJjGQknCLo0CKtuEIyD5xBKYVz3GLofLKqCNGDYdUIxwgaBBpssNIDGQIDAQABAoGBAKmzw1taiRawA9VQegRkKQF7ZXwMOjTvwcme1H74CYUU5MOEfzOgDbW7kgvNcJ8dwlg/sh7uNsppZjif/4UUw5R7bSu33m1sIyglmKUYTU7Kw+ETVAPgwkQjJhekV/pDr143vmchAblD4RqQZTneojTkvYgci4RkHHHIIZ8lClIBAkEA/nEyCKzl0gxULWMd0HKLctcwDu6NPWycffFzSg/+k1+h0GlSTp2E8J6DKOYnrlQYvK2/BnbFPfrbEySi+7c86QJBANNOExrr7xl54JnlZxbXNDnNrql2brPk1DsV/3Lo3Tmt8NuVqiyohVE8Vs/CPRqTTSPoTV4TwSscB4Torlox9rECQB9tne+CY7TJPxCIIKOhsmXR/KargpimtMG9tC7ewOQ1OMiEad06CbSq76p6m0YmLxQHJgRHYV+hf7Pin5sV7BkCQQC69KxAuJk/YC9R2r/AXL4vmoU8GLZP4lnIwWjXwaLiwryFfEEp7BywyINCpOgtWED7UTEK2M2jl9QrSzfgQ66xAkBm2RI+8onm/4PVKtOt8tqLjfsFGMR3g0aUwgSbznc0Xg9dfU+YUgqfQnyAQHt9jG3/SBdmIrYoWwb7TqJZLkZI-----END RSA PRIVATE KEY-----', 'alipay_app_public_key' => '-----BEGIN PUBLIC KEY-----MIGfMA0GCSqGASDEDEDEBAQUAA4GNADCBiQKBgQDSBOW3jdthyqSBMNJ8P+BQnfoKpL29BtvACW1gr8YhXh8EqpBUnUDdQgi8uYnprXBbR5O1DVnIqLKG9loEn3Rc2iqpnj3M3nSShuVByjyJjQ+DAIG2/cgJjGQknCLo0CKtuEIyD5xBKYVz3GLofLKqCNGDYdUIxwgaBBpssNIDGQIDAQAB-----END PUBLIC KEY-----', ], 'banned' => false, 'banned_msg' => null, 'description' => 'alipay description',]);
String subAppId = "app_rbDmXLHmLqbTLKm9"; Map<String, Object> params = new HashMap<>();params.put("channel", "bfb");params.put("description", "Channel params description.");Map<String, Object> channelParams = new HashMap<>();channelParams.put("fee_rate", 60);channelParams.put("bfb_sp", "1600200000");channelParams.put("bfb_key", "A9lUEVtdrrQobDasdfzM2rThSNpXVELt");params.put("params", channelParams); // 创建子商户 channel 对象// 参数一: SubApp id// 参数二: paramsChannel obj = Channel.create(subAppId, params);
pingpp.subApps.createChannel( APP_ID, 'app_rbDmXLHmLqbTLKm9', // SUB_APP_ID { 'channel': 'bfb', 'params': { 'fee_rate': 60, 'bfb_sp': '1600200000', 'bfb_key': 'A9lUEVtdrraaaaHgzkzM2rThSNpXVELt' }, 'description': 'Your description' }, function(err, data) { // YOUR CODE if (err != null){ console.log(err); } console.log(data); });
params = { "banned_msg": None, "channel": "alipay", "description": "Your description", "params": { "alipay_account": "example@example.com", "alipay_app_id": "2016666666666666", "alipay_app_public_key": "-----BEGIN PUBLIC KEY-----\nMIGeMA0GCSqGSIb3DQEBAQUAA4GMADCBiAKBgFYBbIo698oeToWRvAcqTw4TEZKa\nwKPIJrZ4pbZPooSriP6aqXIqRnM3734/gcJso24IZheM+sgz0An8+wN4bQ2Y/qO8\nSOh3HNDPzYuhR+CRajIOkGWUjxmqmi14zcLgWgURrgmdBIccM5BnRSFWdUWZTzez\ngl75CdmtXHmst7LNAgMBAAE=\n-----END PUBLIC KEY-----", "alipay_app_public_key_rsa2": None, "alipay_mer_app_private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC+KDkMaoEy1t+0\nN5tYCgsHJRDogpknCoUVA5aiGBl4E8SyC3gWRB9j6/FUCKYWobUnZoFur3XDd7Bs\ni57vJRQmEow1dYA3PIHAaLE3fzDTm1joJqExfctrS27AqxDWKcKxgDE8hcbhMCgN\nq24BHl+KVCSG7c3X1yY+lO393m7x6CVpSVPerx7PMaW28M+zRdIMHTLPG6v/0r6r\ny/yodjWKoZU7KlpQndgTzChIZIxb0hC578DAaTVBQv9lWenG84S3/s/kzO9j7YFR\nF3dn5XFx5LhzQdfctXmLmyqfUoL23FxDlI3BApAHjKCXdStZdWqFBeffdDK9WZ1/\n7qKigV93AgMBAAECggEABbXPgL/yAUTSkubYk1w52I0UZOcHElUOigMBkvyGR0TQ\ns0gE4yZIiweax5s64ZMZjYVWfaxnLOd7NMc8jpHeeQY1j6VnpED85HpAWBpJrREN\nKmt+i63rXd12BfMdHlFCt3HSCK87uadojICJXR88XzsHncWmWMTtMRPn0afMTRdO\nPwzTqVzRsavl6fuzhgufwMc9ZRJDcEZBAfXcvmGTj8xVqW7G3hsys7rXYODAgLdT\nThXa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"alipay_refund_nopwd": False, "alipay_security_key": "a5srakrbci3nf1pracb52xcs9xlhu8gu", "alipay_sign_type": "rsa", "alipay_version": 1, "fee_rate": 80 } }channel = pingpp.Channel.create(app=pingpp.app_id, sub_app_id='app_ibXHGCzPaLe9fLqH', **params)
params = { :channel => "bfb", :params => { "fee_rate" => 60, "bfb_sp" => "1600330000", "bfb_key" => "aaaacGsdBdErycpTxs3KMQ3cQkawZvzC" }, :description => "channel info" } channel_info = Pingpp::Channel.create(params, {:sub_app => get_sub_app_id})
func (c *ChannelDemo) New() (*pingpp.Channel, error) { params := &pingpp.ChannelParams{ Channel: "alipay", Params: map[string]interface{}{ "fee_rate": 60, "alipay_pid": "2088501666666666", "alipay_account": "account@example.com", "alipay_security_key": "Your security_key", "alipay_mer_app_private_key": `-----BEGIN RSA PRIVATE KEY-----MIICXQIBAAKBgQDSBOW3jdthyqSBMNJ8P+BQnfoKpL29BtvACW1gr8YhXh8EqpBUnUDdQgi8uYnprXBbR5O1DVnIqLKG9loEn3Rc2iqpnj3M3nSShuVByjyJjQ+DAIG2/cgJjGQknCLo0CKtuEIyD5xBKYVz3GLofLKqCNGDYdUIxwgaBBpssNIDGQIDAQABAoGBAKmzw1taiRawA9VQegRkKQF7ZXwMOjTvwcme1H74CYUU5MOEfzOgDbW7kgvNcJ8dwlg/sh7uNsppZjif/4UUw5R7bSu33m1sIyglmKUYTU7Kw+ETVAPgwkQjJhekV/pDr143vmchAblD4RqQZTneojTkvYgci4RkHHHIIZ8lClIBAkEA/nEyCKzl0gxULWMd0HKLctcwDu6NPWycffFzSg/+k1+h0GlSTp2E8J6DKOYnrlQYvK2/BnbFPfrbEySi+7c86QJBANNOExrr7xl54JnlZxbXNDnNrql2brPk1DsV/3Lo3Tmt8NuVqiyohVE8Vs/CPRqTTSPoTV4TwSscB4Torlox9rECQB9tne+CY7TJPxCIIKOhsmXR/KargpimtMG9tC7ewOQ1OMiEad06CbSq76p6m0YmLxQHJgRHYV+hf7Pin5sV7BkCQQC69KxAuJk/YC9R2r/AXL4vmoU8GLZP4lnIwWjXwaLiwryFfEEp7BywyINCpOgtWED7UTEK2M2jl9QrSzfgQ66xAkBm2RI+8onm/4PVKtOt8tqLjfsFGMR3g0aUwgSbznc0Xg9dfU+YUgqfQnyAQHt9jG3/SBdmIrYoWwb7TqJZLkZI-----END RSA PRIVATE KEY-----`, "alipay_app_public_key": `-----BEGIN PUBLIC KEY-----MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDSBOW3jdthyqSBMNJ8P+BQnfoKpL29BtvACW1gr8YhXh8EqpBUnUDdQgi8uYnprXBbR5O1DVnIqLKG9loEn3Rc2iqpnj3M3nSShuVByjyJjQ+DAIG2/cgJjGQknCLo0CKtuEIyD5xBKYVz3GLofLKqCNGDYdUIxwgaBBpssNIDGQIDAQAB-----END PUBLIC KEY-----`, }, Banned: false, BannedMsg: "", Description: "alipay description", } return channel.New(c.demoAppID, c.demoSubAppID, params)}
var param = new Dictionary<string, object> { {"channel", "bfb"}, {"banned", false}, {"banned_msg", null}, {"description", "The description for bfb"}, {"params", new Dictionary<string,object>{ {"bfb_sp", "百度钱包合作密钥"}, {"fee_rate", 30}, {"bfb_key", "百度钱包合作密钥"} }}}; Console.WriteLine(SubAppChannel.Create(appId, subAppId, param));
Ping++ 收到创建子商户渠道参数请求后返回给你的服务器一个 Channel 对象,下面是 Channel 对象的一个示例:
{ "object": "channel", "channel": "alipay", "banned": false, "banned_msg": "your banned_msg", "created": 1494854723, "description": "Your alipay description", "params": { "alipay_pid": "2088111111111111", "alipay_app_id": "2016666666666666", "alipay_account": "example@example.com", "alipay_security_key": "a5srakrbci3nf1pracb52xcs9xlhu8gu", "alipay_mer_app_private_key": "-----BEGIN PRIVATE KEY----- your private key -----END PRIVATE KEY-----", "alipay_app_public_key": "-----BEGIN PUBLIC KEY----- your public key -----END PUBLIC KEY-----", "alipay_mer_app_private_key_rsa2": null, "alipay_app_public_key_rsa2": null, "alipay_version": 1, "alipay_refund_nopwd": true }}
子商户渠道参数查询
Ping++ 提供接口可以查询一个已创建的子商户渠道对象。
子商户渠道参数查询
$sub_app_channel = \Pingpp\Channel::retrieve('app_1Gqj58ynP0mHeX1q', 'alipay');
String subAppId = "app_rbDmXLHmLqbTLKm9";String channel = "bfb"; // 查询子商户 app 渠道参数方法// 参数一: subAppId// 参数二: channel 需要查询的渠道名Channel obj = Channel.retrieve(subAppId, channel);
pingpp.subApps.retrieveChannel( APP_ID, 'app_rbDmXLHmLqbTLKm9', // sub_app ID 'bfb', // 渠道名字 function(err, data) { // YOUR CODE if (err != null){ console.log(err); } });
channel_list = pingpp.Channel.retrieve(app=pingpp.app_id, sub_app_id='app_ibXHGCzPaLe9fLqH', channel='alipay')
channel_info = Pingpp::Channel.retrieve( "bfb", { :sub_app => get_sub_app_id })
func (c *ChannelDemo) Get() (*pingpp.Channel, error) { return channel.Get(c.demoAppID, c.demoSubAppID, "alipay")}
SubAppChannel.Retrieve(appId, subAppId, "bfb")
注意事项
- 一个子商户应用在一个渠道下只能配置最多一套渠道参数;
- 子商户渠道参数配置不支持测试模式(API Test Key);
下一步订单