H5调用支付宝、公众号收银台
- 调用预下单接口,参见接口文档,可获得H5收银台路径,字段名称为payUrl。
- 跳转至payUrl,即可打开H5收银台。
window.location = payUrl
h5调用小程序收银台
- 调用预下单接口,参见接口文档,可获得小程序短链,字段名称为payUrl
- 跳转至payUrl,即可拉起聚合收银台小程序。
window.location = payUrl
APP调用支付宝收银台
- 调用预下单接口,参见接口文档,可获得唤起支付宝的alipays协议,字段名称为payUrl
- app只能识别
http://或https://开头的url
,不识别alipays协议,所以需要通过webview打开payUrl。详细代码可参考支付宝官方文档
APP调用小程序收银台
iOS调用
添加微信scheme到白名单中
调用预下单接口,参加接口文档
拉起小程序。代码示例
WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
launchMiniProgramReq.userName = @"原始id"; //聚合收银台小程序的原始id
// 将预下单接口返回的数据解密、转码拼接到路径后
launchMiniProgramReq.path = @"pages/index/index?businessData=%7B%22rpcError%22%3Afalse%2C%22data%22%3A%7B%22mercId%22%3A%22826521057227893%22%2C%22encryData%22%3A%22fb2d48b94f1522ac03305f373dbf9881%22%2C%22amount%22%3A%222%22%2C%22orderEfficientTime%22%3A%2220240321174749%22%2C%22orderId%22%3A%221711012613937%22%2C%22orderCreateTime%22%3A%2220240321171749%22%2C%22reqMsgId%22%3A%221711012668967%22%7D%2C%22suffixCode%22%3A0%7D";
NSDictionary *dic = @{@"rpcError": @NO,@"data":@{@"mercId":@"826521057227893",@"encryData":@"4b02fe998aabd702be94bbd5a175c829",@"amount":@"2",@"orderEfficientTime":@"20240321173910",@"orderId":@"1711012139844",@"orderCreateTime":@"20240321170910",@"reqMsgId":@"1711012148430"},@"suffixCode":@"0"};
NSString *bus = [dic mj_JSONString];
launchMiniProgramReq.path = [NSString stringWithFormat:@"pages/index/index?businessData=%@",bus];
// launchMiniProgramReq.extDic = dic;
// launchMiniProgramReq.extMsg = bus;
launchMiniProgramReq.miniProgramType = WXMiniProgramTypePreview; //拉起小程序的类型,选正式版
[WXApi sendReq:launchMiniProgramReq completion:^(BOOL success) {
}];
Android调用
- 调用预下单接口,参加接口文档
- 拉起小程序。代码示例:
package com.ys.openwechat;
import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import androidx.annotation.Nullable;
import com.tencent.mm.opensdk.modelbiz.WXLaunchMiniProgram;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.ysepay.merchant.R;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
public class MainActivity extends Activity implements View.OnClickListener {
// APP_ID 替换为你的应用在微信开放平台申请到的appid
private static final String APP_ID = "";
// IWXAPI 是第三方app和微信通信的openApi接口
private IWXAPI api;
private EditText mEditText, mEditText1, mEditText2;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initview();
initData();
}
private void initData() {
}
//注册
private void regToWx(String AppId) {
if (!TextUtils.isEmpty(AppId)) {
// 通过WXAPIFactory工厂,获取IWXAPI的实例 APP_ID 应用(App)的 AppId
api = WXAPIFactory.createWXAPI(this, AppId, true);
// 将应用的appId注册到微信
api.registerApp(AppId);
} else
Toast.makeText(MainActivity.this, "参数为空", Toast.LENGTH_SHORT);
}
private void initview() {
mEditText = findViewById(R.id.editTextNumber);
mEditText1 = findViewById(R.id.editTextNumber1);
mEditText2 = findViewById(R.id.editTextNumber2);
findViewById(R.id.button).setOnClickListener(MainActivity.this);
findViewById(R.id.button1).setOnClickListener(MainActivity.this);
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.button:
regToWx(mEditText.getText().toString());
break;
case R.id.button1:
wxsendReq(mEditText1.getText().toString(), mEditText2.getText().toString());
break;
}
}
//小程序调用
private void wxsendReq(String userName, String miniprogramType) {
WXLaunchMiniProgram.Req req = new WXLaunchMiniProgram.Req();
req.userName = userName; // userName填聚合收银台小程序原始id
// 预下单接口返回的businessData
String s = "{\"rpcError\":false,\"data\":{\"mercId\":\"826521057227893\",\"encryData\":\"4b02fe998aabd702be94bbd5a175c829\",\"amount\":\"2\",\"orderEfficientTime\":\"20240321173910\",\"orderId\":\"1711012139844\",\"orderCreateTime\":\"20240321170910\",\"reqMsgId\":\"1711012148430\"},\"suffixCode\":0}";
String path = "";
try {
path = URLEncoder.encode(s, "UTF-8"); // businessData需要解密,转码
req.path = "pages/index/index?businessData=" + path; ////拉起小程序页面的路径和参数 "。
//req.miniprogramType = WXLaunchMiniProgram.Req.MINIPTOGRAM_TYPE_RELEASE;// 打开正式版
req.miniprogramType = Integer.valueOf(miniprogramType);
api.sendReq(req);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
}