我正在使用jamaa-smpp
发送消息。它可以工作,但发件人ID为00000,而不是我想要的名称。我将TON
和NPI
用于在提交的sm中启用字母数字发件人,如下面的代码所示,但仍为00000。发送消息时,我无法将sm链接到客户端。>
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ss_Click(object sender, EventArgs e)
{
var sm = new SubmitSm();
sm.SourceAddress.Ton = JamaaTech.Smpp.Net.Lib.TypeOfNumber.Aphanumeric;
sm.SourceAddress.Npi = JamaaTech.Smpp.Net.Lib.NumberingPlanIndicator.ISDN;
sm.DestinationAddress.Ton = JamaaTech.Smpp.Net.Lib.TypeOfNumber.International;
sm.DestinationAddress.Npi = JamaaTech.Smpp.Net.Lib.NumberingPlanIndicator.ISDN;
TextMessage msg = new TextMessage();
msg.DestinationAddress ="96565565655556"; //Receipient number
msg.SourceAddress = "NYCOMPANYNAME"; //Originating number
msg.Text = "text text text text";
msg.RegisterDeliveryNotification = true; //I want delivery notification for this message
SmppClient client = GetSmppClient();
client.BeginSendMessage(msg, SendMessageCompleteCallback, client);
}
private void client_ConnectionStateChanged(object sender, ConnectionStateChangedEventArgs e)
{
switch (e.CurrentState)
{
case SmppConnectionState.Closed:
//Connection to the remote server is lost
//Do something here
e.ReconnectInteval = 60000; //Try to reconnect after 1 min
break;
case SmppConnectionState.Connected:
//A successful connection has been established
break;
case SmppConnectionState.Connecting:
//A connection attemp is still on progress
break;
}
}
private SmppClient GetSmppClient()
{
SmppClient client = new SmppClient();
System.Threading.Thread.Sleep(9000);
SmppConnectionProperties properties = client.Properties;
properties.SystemID = "id";
properties.Password = "pass";
properties.Port = xxxxx; //IP port to use
properties.Host = "x.x.x.x"; //SMSC host name or IP Address
properties.SystemType = "SMPP";
properties.DefaultServiceType = "SMPP";
client.AutoReconnectDelay = 3000;
client.KeepAliveInterval = 15000;
client.Start();
System.Threading.Thread.Sleep(9000);
return client;
}
private static void SendMessageCompleteCallback(IAsyncResult result)
{
try
{
SmppClient client = (SmppClient)result.AsyncState;
client.EndSendMessage(result);
}
catch (Exception e)
{
}
}
}
我希望发件人名称为MYCOMPANYNAME,而不是00000000。
答案 0 :(得分:1)
您需要将'NPI'设置为unknown,将'ton'设置为字母数字和
public class ShowQuizActivity extends AppCompatActivity implements View.OnClickListener {
final static int INTERVAL = 1000;
final static int TIMEOUT = 7000;
int progressValue = 0;
List<Question> questionList;
CountDownTimer mCountDownTimer;
ProgressBar progressBar;
Button btnA,btnB,btnC,btnD;
TextView txtScore,txtQuestionNum,txtQuestion;
int score = 0,index = 0,thisQuestion = 0,totalQuestion,correctAnswer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_quiz);
questionList = new ArrayList<>();
progressBar = findViewById(R.id.progressBar);
txtQuestion = findViewById(R.id.question);
txtQuestionNum = findViewById(R.id.quNum);
txtScore = findViewById(R.id.score);
btnA = findViewById(R.id.option1);
btnB = findViewById(R.id.option2);
btnC = findViewById(R.id.option3);
btnD = findViewById(R.id.option4);
btnA.setOnClickListener(this);
btnB.setOnClickListener(this);
btnC.setOnClickListener(this);
btnD.setOnClickListener(this);
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference questionRef = rootRef.child("Question");
ValueEventListener valueEventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//List<Question> questionList = new ArrayList<>();
for(DataSnapshot ds : dataSnapshot.getChildren()) {
Question q = ds.getValue(Question.class);
questionList.add(q);
String answer = q.getAnswer();
String option1 = q.getOption1();
String option2 = q.getOption2();
String option3 = q.getOption3();
String option4 = q.getOption3();
String question = q.getQuestion();
Log.d("=>", answer + "/" + option1 + "/" + option2 + "/" + option3 + "/" + option4 + "/" + question);
}
//Do what you need to do with your list
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Log.d("=>", databaseError.getMessage()); //Don't ignore errors!
}
};
questionRef.addListenerForSingleValueEvent(valueEventListener);
}
@Override
public void onClick(View view) {
mCountDownTimer.cancel();
if (index < totalQuestion){
Button ClickedButton = (Button) view;
if (ClickedButton.getText().equals(questionList.get(index).getAnswer())){
score+=10;
correctAnswer++;
showQuestion(index++);
}
else {
showQuestion(++index);
}
txtScore.setText(String.format("%d",score));
}
}
private void showQuestion(int index) {
if (index < totalQuestion){
thisQuestion++;
txtQuestionNum.setText(String.format("%d/%d",thisQuestion,totalQuestion));
progressBar.setProgress(0);
progressValue = 0;
txtQuestion.setText(questionList.get(index).getQuestion());
btnA.setText(questionList.get(index).getOption1());
btnB.setText(questionList.get(index).getOption2());
btnC.setText(questionList.get(index).getOption3());
btnD.setText(questionList.get(index).getOption4());
}
else {
Intent intent = new Intent(this,ScoreActivity.class);
Bundle dataSend = new Bundle();
dataSend.putInt("SCORE",score);
dataSend.putInt("TOTAL",totalQuestion);
dataSend.putInt("CORRECT",correctAnswer);
intent.putExtras(dataSend);
startActivity(intent);
finish();
}
}
@Override
protected void onResume() {
super.onResume();
totalQuestion = questionList.size();
mCountDownTimer = new CountDownTimer(TIMEOUT,INTERVAL) {
@Override
public void onTick(long l) {
progressBar.setProgress(progressValue);
progressValue++;
}
@Override
public void onFinish() {
mCountDownTimer.cancel();
showQuestion(++index);
}
};
showQuestion(++index);
}
}
Question class is here:
public class Question {
private String answer,option1,option2,option3,option4,question;
public Question() {
}
public Question(String answer, String option1, String option2, String option3, String option4, String question) {
this.answer = answer;
this.option1 = option1;
this.option2 = option2;
this.option3 = option3;
this.option4 = option4;
this.question = question;
}
public String getAnswer() {
return answer;
}
public void setAnswer(String answer) {
this.answer = answer;
}
public String getOption1() {
return option1;
}
public void setOption1(String option1) {
this.option1 = option1;
}
public String getOption2() {
return option2;
}
public void setOption2(String option2) {
this.option2 = option2;
}
public String getOption3() {
return option3;
}
public void setOption3(String option3) {
this.option3 = option3;
}
public String getOption4() {
return option4;
}
public void setOption4(String option4) {
this.option4 = option4;
}
public String getQuestion() {
return question;
}
public void setQuestion(String question) {
this.question = question;
}
}
不是msg.SourceAddress =“ MYCOMPANYNAME”;
希望它会有所帮助。如果您认为此答案有用,请标记出来。
答案 1 :(得分:0)
更新后的代码是:
{
protected void send_Click(object sender, EventArgs e)
{
var sm = new SubmitSm();
sm.SourceAddress.Npi = JamaaTech.Smpp.Net.Lib.NumberingPlanIndicator.Unknown;
sm.SourceAddress.Ton = JamaaTech.Smpp.Net.Lib.TypeOfNumber.Aphanumeric
sm.DestinationAddress.Ton = JamaaTech.Smpp.Net.Lib.TypeOfNumber.International;
sm.DestinationAddress.Npi = JamaaTech.Smpp.Net.Lib.NumberingPlanIndicator.Unknown;
TextMessage msg = new TextMessage();
msg.DestinationAddress ="123456789"; //Receipient number
msg.Text = "test test";
msg.RegisterDeliveryNotification = true; //I want delivery notification for this message
SmppClient client = GetSmppClient();
client.BeginSendMessage(msg, SendMessageCompleteCallback, client);
}
private void client_ConnectionStateChanged(object sender, ConnectionStateChangedEventArgs e)
{
switch (e.CurrentState)
{
case SmppConnectionState.Closed:
e.ReconnectInteval = 60000; //Try to reconnect after 1 min
break;
case SmppConnectionState.Connected:
break;
case SmppConnectionState.Connecting:
break;
}
}
private SmppClient GetSmppClient()
{
SmppClient client = new SmppClient();
System.Threading.Thread.Sleep(9000);
SmppConnectionProperties properties = client.Properties;
properties.SystemID = "xxxxxx";
properties.Password = "xxxxxx";
properties.Port = 10000; //IP port to use
properties.Host = "xx.xx.xx.xx"; //SMSC host name or IP Address
properties.SystemType = "SMPP";
properties.DefaultServiceType = "SMPP";
properties.SourceAddress = "MYCOMPANY";
properties.AddressNpi = NumberingPlanIndicator.Unknown;
properties.AddressTon = TypeOfNumber.Aphanumeric;
properties.DefaultEncoding = DataCoding.Latin1;
client.AutoReconnectDelay = 3000;
client.KeepAliveInterval = 15000;
client.Start();
System.Threading.Thread.Sleep(9000);
return client;
}
private static void SendMessageCompleteCallback(IAsyncResult result)
{
try
{
SmppClient client = (SmppClient)result.AsyncState;
client.EndSendMessage(result);
}
catch (Exception e)
{
}
}
}
答案 2 :(得分:0)
public class MyTextMessage : TextMessage
{
protected override SubmitSm CreateSubmitSm(SmppEncodingService smppEncodingService)
{
var sm = base.CreateSubmitSm(smppEncodingService);
sm.SourceAddress.Ton = JamaaTech.Smpp.Net.Lib.TypeOfNumber.Aphanumeric;
sm.SourceAddress.Npi = JamaaTech.Smpp.Net.Lib.NumberingPlanIndicator.Unknown;
return sm;
}
}
和
TextMessage msg = new MyTextMessage();