2025年03月31日/ 浏览 80
weixin://
协议,该协议允许App直接启动微信并执行特定操作。weixin://addfriend/businesscard?ticket=
的方式。其中ticket
是你在服务器端通过微信API获得的加好友凭证。“`swift
import UIKit
import MobileCoreServices // 导入框架以使用URL Scheme
func openWeChatAddFriend() {
let url = NSURL(string: “weixin://addfriend/businesscard?ticket=YOURTICKETHERE”)!
UIApplication.shared.open(url as URL, options: [:], completionHandler: nil)
}
“`
在Swift代码中,你需要替换YOUR_TICKET_HERE
为从服务器端获取的实际ticket值。
“`kotlin
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val url = “weixin://addfriend/businesscard?ticket=YOURTICKETHERE”
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
startActivity(intent)
}
}
“`
在Kotlin代码中,同样需要替换YOUR_TICKET_HERE
为服务器返回的实际ticket值。
weixin://
协议的使用,还需要对微信开放平台API有一定的了解和使用经验。